MyBatis(八)联合查询 级联属性封装结果集

(1)接口中编写方法

1 public Emp getEmpandDept();

(2)编写Mapper文件

 1  <resultMap type="com.eu.bean.Emp" id="emp2">
 2       <id column="id" property="id"/>
 3       <result column="last_name" property="lastName"/>
 4       <result column="gender" property="geder"/>
 5       <result column="email" property="email"/>
 6       <result column="id" property="dept.id"/>
 7       <result column="dept_name" property="dept.deptName"/>
 8   </resultMap>
 9 
10  <select id="getEmpandDept" resultMap="emp2">
11       SELECT * 
12       FROM emp e
13     JOIN dept d
14     ON e.d_id=d.id
15   </select>

 

posted @ 2019-04-16 23:13  司徒二条  阅读(279)  评论(0编辑  收藏  举报