MyBatis(十一) 嵌套结果集的方式,使用collection标签定义关联的集合类型的属性封装规则


(1)接口中编写方法

public Dept getDeptPlusById(Integer id);

(2)Mapper文件

 1   <resultMap type="com.eu.bean.Dept" id="MyPlus">
 2         <id column="id" property="id"/>
 3         <result column="dept_name" property="deptName"/>
 4         <collection property="emps" ofType="com.eu.bean.Emp">
 5             <id column="id" property="id"/>
 6             <result column="last_name" property="lastName"/>
 7             <result column="gender" property="geder"/>
 8         </collection>
 9     </resultMap>
10     
11     <!-- public Dept getDeptPlusById(Integer id); -->
12     <select id="getDeptPlusById" resultType="MyPlus">
13         SELECT *FROM dept d
14         JOIN emp e
15         ON d.id=e.d_id
16         WHERE d.id=#{id}
17     </select>

 

欢迎添加本人微信,带你加入Java学习交流群,还有学习资料等你获取。

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM