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

猜你喜欢

转载自www.cnblogs.com/xiximayou/p/12219236.html
今日推荐