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);
        }
    ​
    }
相关推荐
会编程的林俊杰15 分钟前
Mapper解析
java·mybatis
Tan_Ying_Y2 小时前
Mybatis的mapper文件中#和$的区别
java·tomcat·mybatis
失足成万古风流人物8 小时前
面试官问MyBatis/OpenFeign的原理?我手搓了个MyHttp怼回去!(反八股版)
mybatis·springboot·openfeign·动态代理
fanruitian9 小时前
springboot-mybatisplus-demo
spring boot·后端·mybatis·mybatisplus
invicinble1 天前
spring相关系统性理解,企业级应用
java·spring·mybatis
gAlAxy...1 天前
MyBatis 核心配置文件 SqlMapConfig.xml 全解析
xml·mybatis
2501_916766541 天前
【Mybatis】延迟加载与多级缓存
缓存·mybatis
YDS8292 天前
MyBatis-Plus精讲 —— 从快速入门到项目实战
java·后端·spring·mybatis·mybatis-plus
库库林_沙琪马2 天前
7、集成MyBatis
spring boot·mybatis
2501_916766542 天前
【Mybatis】注解开发与事务
mybatis