(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學習交流群,還有學習資料等你擷取。

轉載于:https://www.cnblogs.com/wanerhu/p/10747386.html