association元素:一对一查询结果集结果集的映射
property属性:实体类和数据库不能直接映射的那个属性或者是那几个属性
column:外键列的名称,说白了就是两个表之间连接的那个外键
Javatype属性:嵌套的resultMap返回的结果类型(这个属性原先属于哪个类的就写那个类的名字)
result
Employee类
public class Employee {
private int eid;
private String eno;
private String ename;
private Department dept;
public int getEid() {
return eid;
}
public void setEid(int eid) {
this.eid = eid;
}
public String getEno() {
return eno;
}
public void setEno(String eno) {
this.eno = eno;
}
public String getEname() {
return ename;
}
public void setEname(String ename) {
this.ename = ename;
}
public Department getDept() {
return dept;
}
public void setDept(Department dept) {
this.dept = dept;
}
}
Department类
package bean1;
public class Department {
private int did;
private String dno;
private String dname;
public int getDid() {
return did;
}
public void setDid(int did) {
this.did = did;
}
public String getDno() {
return dno;
}
public void setDno(String dno) {
this.dno = dno;
}
public String getDname() {
return dname;
}
public void setDname(String dname) {
this.dname = dname;
}
}
结果集映射
<resultMap type="Employee" id = "empResult">
<result property="eid" column="eid" />
<result property="eno" column="eno" />
<result property="ename" column="ename" />
<association property="dept" column="deptid" javaType="Deptment"
resultMap="deptResult"></association>
</resultMap>
<resultMap type="Deptment" id="deptResult">
<result property="did" column="did" />
<result property="dno" column="dno" />
<result property="dname" column="dname" />
</resultMap>