mybatis一对多几种mapper写法

本文详细探讨了MyBatis中处理一对多关系的多种Mapper写法,包括在映射文件中配置和使用ResultMap的方式,展示了如何有效地获取并展示每个公司及其对应的全部员工信息。
摘要由CSDN通过智能技术生成
create table t_company
(
  id        NUMBER(12) not null,
  name      VARCHAR2(128),
  code      VARCHAR2(32),
  address   VARCHAR2(256),
  telephone VARCHAR2(18)
)

create table t_employee
(
  id         NUMBER(12) not null,
  name       VARCHAR2(48),
  sex        NUMBER(1),
  job        VARCHAR2(48),
  salary     NUMBER(12,2),
  company_id NUMBER(12)
)
@Data
public class Company implements Serializable {
    private Integer id;
    private String name;
    private String code;
    private String address;
    private String telephone;
    private List<Employee> employees;
}

@Data
public class Employee implements Serializable {
    private Integer id;
    private String name;
    private int sex;
    private String job;
    private double salary;
    private Integer companyID;
}

输出各个公司以及所属员工信息:

   <!--mothod one -->
   <resultMap id="companyOne" type="com.example.mybatis01.entity.Company">
        <id column="id" property="id"></id>
        <result column="name" property="name"></result>
        <result column="code" property="code"></result>
        <result column="address" property="address"></result>
        <result column="telephone" property="telephone"></result>
        <collection property="employees"  ofType="com.example.mybatis01.entity.Employee"
                    javaType="java.util.ArrayList
  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值