mybatis文件映射之利分布查询时传递多列值 (七)

时间:2022-07-23
本文章向大家介绍mybatis文件映射之利分布查询时传递多列值 (七),主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

第一步查询:

    <resultMap type="com.gong.mybatis.bean.Department" id="MyDeptStep">
        <id column="id" property="id"/>
        <result column="dept_name" property="deptName"/>
        <collection property="employee" select="com.gong.mybatis.dao.EmployeeMapperPlus.getEmpsByDeptId"
        column="id">    
        </collection>
    </resultMap>
    <select id="getDeptByIdStep" resultMap="MyDeptStep">
        select id,dept_name from tbl_department where id=#{id}
    </select>

第二步查询:

    
    <select id="getEmpsByDeptId" resultType="com.gong.mybatis.bean.Employee">
        select * from tbl_employee where d_id=#{deptId}
    </select>

我们可以将<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关闭全局开启的延迟加载。