使用collection:分段查询结果集

 

 

1.在人员接口书写方法

public List<Employee> getEmpsByDeptId(Integer deptId);

2在人员映射文件中进行配置

<!-- public List<Employee> getEmpsByDeptId(Integer deptId); -->
<select id="getEmpsByDeptId" resultType="com.atguigu.mybatis.bean.Employee">
select * from tbl_employee where did=#{deptId}
</select>

3在部门中接口书写方法

public Department getDeptByIdStep(Integer id);

2在部门映射文件中进行配置

<!-- collection:分段查询 -->
<resultMap type="com.atguigu.mybatis.bean.Department" id="MyDeptStep">
<id column="id" property="id"/>
<id column="dname" property="departmentName"/>

<!-- 扩展:多列的值传递过去:
将多列的值封装map传递;
column="{key1=column1,key2=column2}"
fetchType="lazy":表示使用延迟加载;
- lazy:延迟
- eager:立即
-->


<collection property="emps"
select="com.atguigu.mybatis.dao.EmployeeMapperPlus.getEmpsByDeptId"
column="{deptId=id}" fetchType="lazy"></collection>
</resultMap>
<!-- public Department getDeptByIdStep(Integer id); -->
<select id="getDeptByIdStep" resultMap="MyDeptStep">
select id,dname from department where id=#{id}
</select>


posted @ 2018-03-12 14:41  逆水乘舟,不进则退  阅读(189)  评论(0编辑  收藏  举报