其他信息不需要改变,可以参考上一篇文章,仅改变Mapper信息如下。
目录
1.2 resultMap添加association实现细节
1.Mapper映射文件信息
1.1改变resultMap的映射类型
<!-- Emp getEmpAndDept(@Param("eid") Integer eid);-->
<select id="getEmpAndDept" resultMap="empAndDeptResultMapTwo">
select * from t_emp left join t_dept on t_emp.did = t_dept.did where t_emp.eid = #{eid}
</select>
1.2 resultMap添加association实现细节
association: 处理多对一映射关系
property: 需要处理多对的映射关系的属性名
Javatype: 该属性的类型
<resultMap id="empAndDeptResultMapTwo" type="Emp">
<id property="eid" column="eid"></id>
<result property="age" column="age"></result>
<result property="sex" column="sex"></result>
<result property="email" column="email"></result>
<association property="dept" javaType="Dept">
<id property="did" column="did"></id>
<result property="deptName" column="dept_name"></result>
</association>
</resultMap>