Mybatis一对多查询


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

 

转载于:https://www.cnblogs.com/xuesheng/p/7481818.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值