zoukankan      html  css  js  c++  java
  • 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关闭全局开启的延迟加载。

  • 相关阅读:
    写了一个Rijndael工具类
    使用bcel动态创建class
    有感于大理古城的天主教堂
    joj 1089 &&zoj 1060&&poj 1094 以及wa的分析和数据
    joj1026
    joj 1317
    joj 1171
    joj 2343
    joj 1078 hdu 1116
    joj 1189
  • 原文地址:https://www.cnblogs.com/xiximayou/p/12219236.html
Copyright © 2011-2022 走看看