<resultMapid="empResultMap"type="Emp"><idproperty="eid"column="eid"/><idproperty="empName"column="emp_name"/><idproperty="age"column="age"/><idproperty="sex"column="sex"/><idproperty="email"column="email"/>resultMap><selectid="getAllEmp"resultMap="empResultMap">
select * from t_emp;
select>
多对一映射关系
①级联属性赋值
<resultMapid="empAndDeptResultMapOne"type="Emp"><idproperty="eid"column="eid"/><idproperty="empName"column="emp_name"/><idproperty="age"column="age"/><idproperty="sex"column="sex"/><idproperty="email"column="email"/><idproperty="dept.did"column="did"/><idproperty="dept.deptName"column="dept_name"/>resultMap><selectid="getEmpAndDept"resultMap="empAndDeptResultMapOne">
select * from t_emp left join t_dept on t_emp.did = t_dept.did where t_emp.eid=#{eid}
select>
②使用association
<resultMapid="empAndDeptResultMapTwo"type="Emp"><idproperty="eid"column="eid"/><idproperty="empName"column="emp_name"/><idproperty="age"column="age"/><idproperty="sex"column="sex"/><idproperty="email"column="email"/><associationproperty="dept"javaType="Dept"><idproperty="did"column="did"/><idproperty="deptName"column="dept_name"/>association>resultMap><selectid="getEmpAndDept"resultMap="empAndDeptResultMapTwo">
select * from t_emp left join t_dept on t_emp.did = t_dept.did where t_emp.eid=#{eid}
select><mappernamespace="com.lotus.mybatis.mapper.DeptMapper"><selectid="getEmpAndDeptByStepTwo"resultType="Dept">
select * from t_dept where did=#{did}
select>mapper>
③分步查询
<resultMapid="empAndDeptByStepResultMap"type="Emp"><idproperty="eid"column="eid"/><idproperty="empName"column="emp_name"/><idproperty="age"column="age"/><idproperty="sex"column="sex"/><idproperty="email"column="email"/><associationproperty="dept"select="com.lotus.mybatis.mapper.DeptMapper.getEmpAndDeptByStepTwo"column="did"fetchType="eager">association>resultMap><selectid="getEmpAndDeptByStepOne"resultMap="empAndDeptByStepResultMap">
select * from t_emp where eid=#{eid}
select>
<resultMapid="deptAndEmpResultMap"type="Dept"><idproperty="did"column="did"/><idproperty="deptName"column="dept_name"/><collectionproperty="emps"ofType="Emp"><idproperty="eid"column="eid"/><idproperty="empName"column="emp_name"/><idproperty="age"column="age"/><idproperty="sex"column="sex"/><idproperty="email"column="email"/>collection>resultMap><selectid="getDeptAndEmp"resultMap="deptAndEmpResultMap">
select * from t_dept left join t_emp on t_dept.did = t_emp.did where t_dept.did=#{did}
select>
<!---DeptMapper.xml><resultMapid="deptAndEmpByStepResultMap"type="Dept"><idproperty="did"column="did"/><resultproperty="deptName"column="dept_name"/><collectionproperty="emps"select="com.lotus.mybatis.mapper.EmpMapper.getDeptAndEmpByStepTwo"column="did">collection>resultMap><selectid="getDeptAndEmpByStepOne"resultMap="deptAndEmpByStepResultMap">
select * from t_dept where did=#{did}
select><selectid="getDeptAndEmpByStepTwo"resultType="Emp">
select * from t_emp where did=#{did}
select>