• 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>
  • 相关阅读:
    辞职信(转贴)
    去掉控件上显示聚焦框
    静态构造函数
    用Excel 公式求 金额的差额
    2020/2/6学习总结
    2020/2/3学习总结
    2020/2/7学习总结
    2020/1/31学习总结
    2020/2/5学习总结
    2020/2/4学习总结
  • 原文地址:https://www.cnblogs.com/xiaoruirui/p/11776308.html
Copyright © 2020-2023  润新知