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