mybatis之resultMap实现一对一查询

1、pojo类

package com.js.mybatis.po;
/**
 * 用户po类
 * 单独使用mybatis时,mapper.xml中的OGNL表达式通过getter()方法来读取pojo类的属性值
 * 当mybatis和spring整合时,spring通过反射来读取pojo类的属性值
 */
import java.util.Date;

public class User {
	@Override
	public String toString() {
		return "User [id=" + id + ", username=" + username + ", sex=" + sex
				+ ", birthday=" + birthday + ", address=" + address + "]";
	}
	private int id;
	private String username;
	private String sex;
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getSex() {
		return sex;
	}
	public void setSex(String sex) {
		this.sex = sex;
	}
	public Date getBirthday() {
		return birthday;
	}
	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	private Date birthday;
	private String address;
}

package com.js.mybatis.po;

import java.io.Serializable;
import java.util.Date;

public class Orders implements Serializable {
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private Integer id;

    private Integer userId;

    private String number;

    private Date createtime;

    private String note;
    
    /**
     * 关联的用户信息
     */
    private User user;
   
    public User getUser() {
		return user;
	}

	@Override
	public String toString() {
		return "Orders [id=" + id + ", userId=" + userId + ", number=" + number
				+ ", createtime=" + createtime + ", note=" + note + ", user="
				+ user + "]";
	}

	public void setUser(User user) {
		this.user = user;
	}

	public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    public String getNumber() {
        return number;
    }

    public void setNumber(String number) {
        this.number = number == null ? null : number.trim();
    }

    public Date getCreatetime() {
        return createtime;
    }

    public void setCreatetime(Date createtime) {
        this.createtime = createtime;
    }

    public String getNote() {
        return note;
    }

    public void setNote(String note) {
        this.note = note == null ? null : note.trim();
    }   
    
}


2、mapper.xml




	
	 
	 
	 
	 
	 
	 
	 	
	 	
	 	
	 	
	 	
	 	
	 	
	 	
	 		
	 		
	 		
	 		
	 		
	 	
	 
	 
	 


3、mapper.java

package com.js.mybatis.mapper;

import java.util.List;

import com.js.mybatis.po.OrderCustom;
import com.js.mybatis.po.Orders;

public interface OrdersMapperCustome {
	public List findOrderUserList()throws Exception;
	public List findOrderUserListResultMap() throws Exception;
}


你可能感兴趣的:(mybatis)