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);
        }
    ​
    }
相关推荐
没有bug.的程序员3 小时前
JAVA面试宝典 - 《MyBatis 进阶:插件开发与二级缓存》
java·面试·mybatis
码不停蹄的玄黓10 小时前
深入理解MyBatis延迟加载:原理、配置与实战优化
java·mybatis·延迟加载
hello早上好14 小时前
JPA、缓存、数据源与连接池、简介
java·mybatis
梁辰兴15 小时前
企业培训笔记:宠物信息管理--实现宠物信息分页查询
笔记·elementui·mybatis·vue3·springboot·宠物
鲁子狄17 小时前
[笔记] 动态 SQL 查询技术解析:构建灵活高效的企业级数据访问层
java·spring boot·笔记·sql·mysql·mybatis
拼搏@1 天前
第十六天,7月10日,八股
java·mybatis
军军君011 天前
基于Springboot+UniApp+Ai实现模拟面试小工具四:后端项目基础框架搭建下
spring boot·spring·面试·elementui·typescript·uni-app·mybatis
超级小忍1 天前
在 Spring Boot 中使用 MyBatis 的 XML 文件编写 SQL 语句详解
xml·spring boot·mybatis
程序猿小D1 天前
[附源码+数据库+毕业论文+答辩PPT+部署教程+配套软件]基于SpringBoot+MyBatis+MySQL+Maven+Vue实现的交流互动管理系统
spring boot·mysql·vue·mybatis·毕业论文·答辩ppt·交流互动
24kHT2 天前
xml映射文件的方式操作mybatis
xml·mybatis