首页  >  文章  >  Java  >  Springboot怎么实现整合pagehelper分页功能

Springboot怎么实现整合pagehelper分页功能

PHPz
PHPz转载
2023-05-10 20:07:041228浏览

一、添加依赖

查找maven中pagehelper的版本

在pom中添加依赖

<dependency>
   <groupId>com.github.pagehelper</groupId>
   <artifactId>pagehelper-spring-boot-starter</artifactId>
      <version>1.2.2</version>
</dependency>

二、使用

网络上很多文章都会说需要在application.properties进行配置

其实完全不需要,默认的设置就已经满足大部分需要了

直接使用即可

@RequestMapping(value = "getApps.do")
public String getApps(Apps apps) {
  PageHelper.startPage(apps.getPageNum(), apps.getPageSize());
  ArrayList<Apps> appsList = appsService.getApps(apps);
  PageInfo<Apps> appsPageInfo = new PageInfo<>(appsList);
  return JSON.toJSONString(appsPageInfo);
}

PageHelper.startPage(需要显示的第几个页面,每个页面显示的数量);

下一行紧跟查询语句,不可以写其他的,否则没有效果。

PageHelper.startPage(apps.getPageNum(), apps.getPageSize());
ArrayList<Apps> appsList = appsService.getApps(apps);

这样只起到了分页效果,对总页面数之类的没有详细信息

Springboot怎么实现整合pagehelper分页功能

如果对页面数量等有需求,则需要加上下面这行

PageInfo<T> appsPageInfo = new PageInfo<>(appsList);

这样就满足了全部的分页要求

Springboot怎么实现整合pagehelper分页功能

以上是Springboot怎么实现整合pagehelper分页功能的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文转载于:yisu.com。如有侵权,请联系admin@php.cn删除