SpringBoot学习-(分页)SpringBoot分页插件PageHelper

744 阅读1分钟

1.添加分页依赖

<!-- springboot分页插件 -->
<dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactId>pagehelper-spring-boot-starter</artifactId>
    <!-- 特别注意版本问题, 看到评论以后得以纠正 -->
    <version>1.2.3</version>
</dependency>

2.配置application.yml

# 分页配置,针对mysql
pagehelper:
  helper-dialect: mysql
  reasonable: true
  support-methods-arguments: true
  params: count=countSql

3.使用插件

/**
     * 
     * @Title: getList
     * @Description: 从数据库中获取所有商品类型列表
     * @param pageNum 当前页
     * @param pageSize 当前页面展示数目
     * @return
     * @throws Exception
     */
    public List<GoodsType> getList(int pageNum, int pageSize) throws Exception {
        //使用分页插件,核心代码就这一行
        PageHelper.startPage(pageNum, pageSize);
        // 获取
        List<GoodsType> typeList = typeDao.getList();
        return typeList;
    }