Mybatis-Plus-Join

1. 简介

官网 https://mybatisplusjoin.com/

2. 基本用法

步骤:

  1. 添加依赖

    XML 复制代码
    <!--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

    java 复制代码
    public interface EmpMapper extends MPJBaseMapper<Emp> {
    }
  3. 测试

    java 复制代码
    @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);
        }
    ​
    }
相关推荐
cheems95272 小时前
[Mybatis] #{ } 与 ${ } 的底层博弈与工程实践
mybatis
2601_9498177217 小时前
Spring Boot3.3.X整合Mybatis-Plus
spring boot·后端·mybatis
LaLaLa_OvO1 天前
mybatis 引用静态常量
java·mybatis
yaodong5181 天前
Spring 中使用Mybatis,超详细
spring·tomcat·mybatis
2601_949815331 天前
Spring Boot中集成MyBatis操作数据库详细教程
数据库·spring boot·mybatis
星晨雪海1 天前
若依框架原有页面功能进行了点位管理改造之列表查询(4)
数据库·sql·mybatis
mldlds1 天前
Spring Boot 集成 MyBatis 全面讲解
spring boot·后端·mybatis
那个失眠的夜1 天前
Spring整合Mybatis实现用户的CRUD
java·spring·mybatis
zjjsctcdl1 天前
Spring Boot 整合 MyBatis 与 PostgreSQL 实战指南
spring boot·postgresql·mybatis
zmsofts2 天前
java面试必问13:MyBatis 一级缓存、二级缓存:从原理到脏数据,一篇讲透
java·面试·mybatis