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);
        }
    ​
    }
相关推荐
就叫_这个吧1 小时前
Java+MySQL+Mybatis+Junit4实现学生信息管理系统
java·mysql·mybatis
噢,我明白了5 小时前
MyBatis-Plus 中IPage的分页查询
java·mybatis
basketball6165 小时前
Redis基础:3. Redis 持久化(重要)
redis·bootstrap·mybatis
Knight_AL8 小时前
MyBatis 报错:Parameter ‘xxx‘ not found 的原因与解决方案
java·tomcat·mybatis
我登哥MVP9 小时前
Spring Boot 从“会用”到“精通”:Converter 原理
java·spring boot·servlet·maven·mybatis·converter
XiYang-DING1 天前
【MyBatis】${}与 #{}的区别
java·tomcat·mybatis
sxlishaobin1 天前
SpringBoot集成MyBatis的SQL拦截器实战
spring boot·sql·mybatis
我登哥MVP1 天前
Spring Boo从“会用”到“精通”:Spring Boot 入门
java·spring boot·后端·spring·maven·intellij-idea·mybatis
浮游本尊1 天前
Day 2 :POST `/plan/save` 保存链路 + MyBatis 写操作
mybatis
cheems95271 天前
[开发日记]Spring Boot + MyBatis-Plus 抽奖系统排障实录:从 JWT 被拦截到雪花 ID 失控,我是怎样一步步修通登录与人员列表的
spring boot·后端·mybatis