第一步查询:
<resultMap type="com.gong.mybatis.bean.Department" id="MyDeptStep"> id column="id" property="id"/> result ="dept_name"="deptName"collection property="employee" select="com.gong.mybatis.dao.EmployeeMapperPlus.getEmpsByDeptId" column> </collection> resultMapselect id="getDeptByIdStep" resultMap> select id,dept_name from tbl_department where id=#{id} select>
第二步查询:
="getEmpsByDeptId" resultType="com.gong.mybatis.bean.Employee" select * from tbl_employee where d_id=#{deptId} >
我们可以将<collection property="employee" select="com.gong.mybatis.dao.EmployeeMapperPlus.getEmpsByDeptId" column="id"> 这里的column="id"改为column="{deptId=id}"。
需要传入多列值时,可以将多列值封装为map进行传递,比如column="{key1=column1,key2=column2}"。
补充:在collection中有fetchType属性,默认为lazy,可以将其设置为eager关闭全局开启的延迟加载。