概述
Mybatis-Plus 提供了分页的功能。
使用分页
Maven 依赖
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.12</version>
</dependency>
配置文件
# 分页配置
pagehelper:
helper-dialect: mysql
reasonable: true
support-methods-arguments: true
params: count=countSql
服务类
@Service
public class DepartmentsServiceImpl extends ServiceImpl<DepartmentsMapper, Departments> implements DepartmentsService {
@Autowired
private DepartmentsMapper departmentsMapper;
@Override
public List<Departments> getList(int pageNum, int pageSize) throws Exception {
//使用分页插件
PageHelper.startPage(pageNum, pageSize);
// 获取List
List<Departments> departmentlist = departmentsMapper.selectList(new QueryWrapper());
return departmentlist;
}
}
测试
http://localhost:8082/getDeptEmpList?pageNum=1&pageSize=3
参考
https://mp.baomidou.com/guide/
https://pagehelper.github.io/docs/howtouse/