项目地址
https://gitee.com/hanscoding/mybatis-plus-helper
引入依赖
<dependency>
<groupId>io.github.githgf</groupId>
<artifactId>mybatis-plus-helper</artifactId>
<version>0.0.2</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.1</version>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>3.4.1</version>
</dependency>
代码示例
/**
* 联查多条记录测试
*/
public List<Student> joinListTest() {
// 主表wrapper
JoinLambdaQueryWrapper<Student> studentWrapper = joinQueryWrapperForTable();
// 副表wrapper
JoinLambdaQueryWrapper<ScoreInfo> scoreWrapper = studentWrapper.innerJoin(ScoreInfo.class, Student::getNo, ScoreInfo::getStuNo);
// 查询指定字段
// studentWrapper.select(Student::getNo);
// scoreWrapper.select(ScoreInfo::getScore, ScoreInfo::getStuScore);
// 查询条件
studentWrapper.in(Student::getId, Arrays.asList(2, 13));
// 排序
scoreWrapper.orderByDesc(ScoreInfo::getScore);
return baseMapper.selectJoinList(studentWrapper);
}
/**
* 联查单条测试
*/
public Student joinOneTest() {
// 主表wrapper
JoinLambdaQueryWrapper<Student> studentWrapper = joinQueryWrapperForTable();
// 副表wrapper
JoinLambdaQueryWrapper<ScoreInfo> scoreWrapper = studentWrapper.innerJoin(ScoreInfo.class, Student::getNo, ScoreInfo::getStuNo);
// 查询指定字段
// studentWrapper.select(Student::getNo);
// scoreWrapper.select(ScoreInfo::getScore, ScoreInfo::getStuScore);
// 查询条件
studentWrapper.eq(Student::getId, 2);
// 排序
// studentWrapper.orderByAsc(Student::getSex);
return baseMapper.selectJoinOne(studentWrapper);
}