zoukankan      html  css  js  c++  java
  • MyBatis一对多

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE mapper
            PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
            "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    
    <!-- namespace表示命名空间  保证它是唯一   cn.itsource.mybatis.dao.impl.ProductDaoImpl + id="getUserById"-->
    <mapper namespace="_04_onetomany.DeptMapper">
        <!-- 一对多 嵌套结果 -->
        <select id="query01" resultMap="deptMp">
            select d.id,d.name,e.id eid,e.name ename  from dept d left join employee e
            on d.id = e.dept_id
        </select>
        <resultMap id="deptMp" type="_04_onetomany.Dept">
                <id column="id" property="id"></id>
                <result column="name" property="name"></result>
                <!--property 类里面属性 javaType集合属性 ofType集合里面类型-->
                <collection property="employees" javaType="arraylist" ofType="_04_onetomany.Employee">
                    <id column="eid" property="id"></id>
                    <result column="ename" property="name"></result>
                </collection>
        </resultMap>
    
        <!-- 一对多嵌套查询 -->
        <select id="query02" resultMap="deptMp1">
            select * from dept
        </select>
        <resultMap id="deptMp1" type="_04_onetomany.Dept">
            <id column="id" property="id"></id>
            <result column="name" property="name"></result>
            <!--property 类里面属性 javaType集合属性 ofType集合里面类型-->
            <collection property="employees" column="id" select="getEmployeeByDeptId">
            </collection>
        </resultMap>
    
        <select id="getEmployeeByDeptId" parameterType="long" resultType="_04_onetomany.Employee">
             select * from employee where dept_id =#{id}
        </select>
    
    
    
    </mapper>
  • 相关阅读:
    php面试题目
    JavaScript表单处理的返回值问题
    超链接在javascript:void(0)时没有事件响应
    php 两个美元符号:可变变量
    [Ubuntu] lampp安装Zend Framework
    [Ubuntu] 安装字体
    php中bindValue 和 bindParam 的区别
    php遍历文件夹(获得文件名)
    php输出一段字符块
    PHP 全角和半角转换函数
  • 原文地址:https://www.cnblogs.com/xiaoruirui/p/11776308.html
Copyright © 2011-2022 走看看