zoukankan      html  css  js  c++  java
  • 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;//关联查询的集合
        }
  • 相关阅读:
    Linux磁盘分区、挂载
    crond任务调度
    Form组件使用
    Django路由系统
    Django中模板简单使用
    ORM常用操作
    IO多路复用
    vscode必装插件
    Flask-RESTful扩展
    flask-caching
  • 原文地址:https://www.cnblogs.com/xuesheng/p/7481818.html
Copyright © 2011-2022 走看看