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);
        }
    ​
    }
相关推荐
北城以北88885 小时前
SSM--MyBatis框架之缓存
java·缓存·intellij-idea·mybatis
凌波粒8 小时前
MyBatis完整教程IDEA版(3)--动态SQL/MyBatis缓存
sql·intellij-idea·mybatis
小马爱打代码10 小时前
MyBatis:进阶 - 动态 SQL、关联查询与缓存
sql·缓存·mybatis
cici1587413 小时前
MyBatis注解的运用于条件搜索实践
java·tomcat·mybatis
fenglllle18 小时前
mybatis-plus SQL 注入漏洞导致版本升级引发的问题
数据库·sql·mybatis
C++chaofan1 天前
MyBatis - Plus学习笔记
java·spring boot·笔记·后端·mysql·架构·mybatis
只因在人海中多看了你一眼2 天前
B.40.3.2-MyBatis核心技术详解与性能优化
性能优化·mybatis
.又是新的一天.2 天前
健身房预约系统SSM+Mybatis(五、预约展示)
前端·mybatis
北城以北88882 天前
SSM--MyBatis框架之动态SQL
java·开发语言·数据库·sql·mybatis
计算机学姐2 天前
基于SpringBoot的公务员考试管理系统【题库组卷+考试练习】
java·vue.js·spring boot·后端·java-ee·intellij-idea·mybatis