<resultMap type="com.neuedu.bean.tbl_dept" id="findDepartByIdMap"> <id column="did" property="id"/> <result column="dept_name" property="deptName"/>
<!--使用collection标签
property属性指定POJO中关联查询的属性,oftype指定关联查询的属性的类型
-->
<collection property="empList" ofType="com.neuedu.bean.tbl_employee" > <id column="eid" property="id"/> <result column="user_name" property="userName"/> <result column="email" property="email"/> <result column="gender" property="gender"/> <result column="d_id" property="dId"/> </collection> </resultMap> <!-- public tbl_dept findDepartById(int id); --> <select id="findDepartById" resultMap="findDepartByIdMap"> select d.id did,d.dept_name,e.id eid,e.user_name,e.email,e.gender,e.d_id from tbl_dept d LEFT JOIN tbl_employee e on d.id=e.d_id where d.id=#{id} </select>
在POJO中将关联查询的集合设置为一个list属性
public class tbl_dept { private int id; private String deptName; private List<tbl_employee>empList;//关联查询的集合 }