首页 > 其他 > 详细

Mybatis一对多查询

时间:2017-09-05 21:30:49      阅读:299      评论:0      收藏:0      [点我收藏+]

<
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;//关联查询的集合
    }

 

Mybatis一对多查询

原文:http://www.cnblogs.com/xuesheng/p/7481818.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!