zoukankan      html  css  js  c++  java
  • resultMap2_关联查询collection分步查询&延迟加载

    1、DepartmentMapper.java添加代码

    public Department getDeptByIdStep(Integer id);

    2、EmployeeMapperPlus.java添加代码

    public Employee getEmpByIdDeptId(Integer deptId);

    3、DepartmentMapper.xml添加代码

    <!-- public Department getDeptByIdStep(Integer id); -->
        <resultMap type="com.atguigu.mybatis.bean.Department" id="MyDeptStep">
            <id column="id" property="id"/>
            <result column="departmentName" property="departmentName"/>
            <collection property="emps" 
                                select="com.atguigu.mybatis.dao.EmployeeMapperPlus.getEmpByIdDeptId"
                                    column="id">
            </collection>    
        </resultMap>
        <select id="getDeptByIdStep" resultMap="MyDeptStep">
            select id,dept_name departmentName from tbl_dept where id=#{id}
        </select>

    注:collection类似于association,先调用getDeptByIdStep方法获得tbl_dept中id的值,在用获取的id值做为参数传入到com.atguigu.mybatis.dao.EmployeeMapperPlus接口中getDeptByIdStep方法得到Employee 的所有参数值,最后封装到Department对象中 

    4、EmployeeMapperPlus.xml添加代码

    <!-- public Employee getEmpByIdDeptId(Integer deptId); -->
        <resultMap type="com.atguigu.mybatis.bean.Employee" id="emps22">
            <id column="id" property="id"/>
            <result column="last_name" property="lastName"/>
        </resultMap>
        <select id="getEmpByIdDeptId" resultMap="emps22">
            select * from tbl_employee where d_id=#{deptId}
        </select>
  • 相关阅读:
    Ubuntu 11.04 安装后要做的20件事情
    Net 服务命令行参考之一
    Openerp约束句型
    Ubuntu进入Shell
    postgreSql基础命令及linux下postgreSql命令
    解决中文乱码的问题
    An error occured while handling a json request
    Java Socket编程
    CentOS 7 中 Docker 的安装和卸载
    Spring Boot整合shiro-登录认证和权限管理
  • 原文地址:https://www.cnblogs.com/2016024291-/p/8253458.html
Copyright © 2011-2022 走看看