• Mybatis一对多查询



    <
    resultMap type="com.neuedu.bean.tbl_dept" id="findDepartByIdMap"> <id column="did" property="id"/> <result column="dept_name" property="deptName"/>
    <!--使用collection标签
      property属性指定POJO中关联查询的属性,oftype指定关联查询的属性的类型
    -->
    <collection property="empList" ofType="com.neuedu.bean.tbl_employee" > <id column="eid" property="id"/> <result column="user_name" property="userName"/> <result column="email" property="email"/> <result column="gender" property="gender"/> <result column="d_id" property="dId"/> </collection> </resultMap> <!-- public tbl_dept findDepartById(int id); --> <select id="findDepartById" resultMap="findDepartByIdMap"> select d.id did,d.dept_name,e.id eid,e.user_name,e.email,e.gender,e.d_id from tbl_dept d LEFT JOIN tbl_employee e on d.id=e.d_id where d.id=#{id} </select>

     在POJO中将关联查询的集合设置为一个list属性

    public class tbl_dept {
        private int id;
        private String deptName;
        private List<tbl_employee>empList;//关联查询的集合
        }
  • 相关阅读:
    【转】selenium自动化测试环境搭建
    【cl】多表查询(内、外连接)
    【cl】子查询应用场景
    udev笔记
    C编译相关
    USB学习笔记-协议
    ARM汇编返回指令
    v4l2框架函数调用关系
    /etc/fstab和/etc/mtab
    各种存储介质的差异
  • 原文地址:https://www.cnblogs.com/xuesheng/p/7481818.html
Copyright © 2020-2023  润新知