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

  • 相关阅读:
    MT【319】分段递推数列
    MT【318】分式不等式双代换
    Centos7环境变量
    VI快捷键
    Centos7 开机自动运行命令
    Centos7 编辑本地DNS解析配置文件
    Centos7修改主机名
    xadmin 自定义过滤器选项
    Centos7网卡配置文件
    Centos7 挂载
  • 原文地址:https://www.cnblogs.com/xiximayou/p/12219236.html
Copyright © 2011-2022 走看看