Mybatis-Plus-Join

1. 简介

官网 https://mybatisplusjoin.com/

2. 基本用法

步骤:

  1. 添加依赖

    <!--mybatis-plus-join-->
    <dependency>
       <groupId>com.github.yulichang</groupId>
       <artifactId>mybatis-plus-join-boot-starter</artifactId>
       <version>1.4.5</version>
    </dependency>
  2. 编辑EmpMapper.java,继承自MPJBaseMapper

    public interface EmpMapper extends MPJBaseMapper<Emp> {
    }
  3. 测试

    @SpringBootTest
    class EmpMapperTest {
    ​
        @Resource
        private EmpMapper empMapper;
    ​
        @Test
        public void selectAll(){
            MPJLambdaWrapper<Emp> wrapper = new MPJLambdaWrapper<Emp>()
                    .selectAll(Emp.class) // 查询Emp类的所有字段
                    .selectAs(Dept::getName, EmpDTO::getDeptName)// 查询Dept类的name字段
                    .leftJoin(Dept.class, Dept::getId, Emp::getDeptId) // 左连接
                    .orderByDesc(Emp::getId);
    ​
            List<EmpDTO> list = empMapper.selectJoinList(EmpDTO.class, wrapper);
            list.forEach(System.out::println);
        }
    ​
      
        @Test
        public void selectByPage(){
            Page<EmpDTO> page = new Page<>(1, 3);
    ​
            empMapper.selectJoinPage(page, EmpDTO.class,
                    new MPJLambdaWrapper<Emp>()
                        .selectAll(Emp.class)
                        .selectAs(Dept::getName, EmpDTO::getDeptName)
                        .leftJoin(Dept.class, Dept::getId, Emp::getDeptId)
                        .eq(Dept::getId, 1));
    ​
            page.getRecords().forEach(System.out::println);
        }
    ​
    }

相关推荐

  1. Mybatis-Plus-Join

    2024-05-26 01:07:09       13 阅读
  2. MyBatis-Plus

    2024-05-26 01:07:09       27 阅读
  3. MyBatis-plus

    2024-05-26 01:07:09       33 阅读
  4. Mybatis-Plus

    2024-05-26 01:07:09       31 阅读

最近更新

  1. Docker 的基本概念和优势

    2024-05-26 01:07:09       0 阅读
  2. Ubuntu 下 Docker安装 2024

    2024-05-26 01:07:09       1 阅读
  3. C#中序列化和反序列化

    2024-05-26 01:07:09       1 阅读
  4. 微服务节流阀:Eureka中服务限流策略的精妙实现

    2024-05-26 01:07:09       1 阅读
  5. LVS集群

    LVS集群

    2024-05-26 01:07:09      1 阅读

热门阅读

  1. 前端人员选择组件封装

    2024-05-26 01:07:09       10 阅读
  2. springboot集成mybatis 单元测试

    2024-05-26 01:07:09       9 阅读
  3. 88道测试工具考核高频题整理(附答案背诵版)

    2024-05-26 01:07:09       9 阅读
  4. 第7周 接口重试机制设计与消息队列

    2024-05-26 01:07:09       9 阅读
  5. 网络240521

    2024-05-26 01:07:09       15 阅读
  6. 鸿蒙全面开发指南:入门、生态安全与资源支持

    2024-05-26 01:07:09       12 阅读
  7. vue编程.js

    2024-05-26 01:07:09       13 阅读
  8. 基于 debian 12 利用 kubeadm 部署 k8s 1.29 版本

    2024-05-26 01:07:09       12 阅读
  9. VUE学习

    VUE学习

    2024-05-26 01:07:09      13 阅读
  10. 模块、包、库的区别

    2024-05-26 01:07:09       10 阅读
  11. docker的使用以及常用命令

    2024-05-26 01:07:09       16 阅读
  12. C语言期末习题之二维数组转置

    2024-05-26 01:07:09       10 阅读