SpringBoot整合MybatisPlus分页插件PageHelper

概述

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/

上一篇:如何用HTML和CSS写一个跳动的爱心


下一篇:ld连接器目标文件elf