1. 程式人生 > >mybatis-一對一/一對多(自關聯)配置檔案

mybatis-一對一/一對多(自關聯)配置檔案

實體類:

public class Department implements Serializable {
    private Integer id;
    private String name;    private Set<Department> childDept;
    private Department parentDept;
    public Department getParentDept() {
        return parentDept;
}

    public void setParentDept(Department parentDept) {
        this
.parentDept = parentDept; } public Set<Department> getChildDept() { return childDept; } public void setChildDept(Set<Department> childDept) { this.childDept = childDept; }
public Integer getId() {
    return id;
}

public void setId(Integer id) {
    this.id = id;
} public String getName() { return name; } public void setName(String name) { this.name = name; }
對映檔案:
<resultMap id="BaseResultMap" type="com.xxx.Department" >
  <id column="id" property="id" jdbcType="INTEGER" />
  <result column="name" property="name" jdbcType="VARCHAR" 
/><association property="parentDept" column="parent_id" select="selectParent" javaType="com.ininwork.inin.po.rights.Department"></association> <collection property="childDept" ofType="com.xxx.Department" select="selectChildren" column="id"></collection> </resultMap>