Home > Java > javaTutorial > How does Springboot integrate the pagehelper paging function?

How does Springboot integrate the pagehelper paging function?

PHPz
Release: 2023-05-10 20:07:04
forward
1300 people have browsed it

1. Add dependencies

Find the version of pagehelper in maven

Add dependencies in pom

<dependency>
   <groupid>com.github.pagehelper</groupid>
   <artifactid>pagehelper-spring-boot-starter</artifactid>
      <version>1.2.2</version>
</dependency>
Copy after login

2 , use

Many articles on the Internet will say that you need to configure application.properties

In fact, it is not necessary at all, the default settings already meet most needs

You can use it directly

@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);
}</apps></apps>
Copy after login

PageHelper.startPage (the number of pages to be displayed, the number of each page to display);

The next line follows the query statement, not allowed Write something else, otherwise it will have no effect.

PageHelper.startPage(apps.getPageNum(), apps.getPageSize());
ArrayList<apps> appsList = appsService.getApps(apps);</apps>
Copy after login

This only has a paging effect, and there is no detailed information about the total number of pages.

How does Springboot integrate the pagehelper paging function?

If there is a demand for the number of pages, etc., you need to add The following line

PageInfo<t> appsPageInfo = new PageInfo(appsList);</t>
Copy after login

thus meets all paging requirements

How does Springboot integrate the pagehelper paging function?

The above is the detailed content of How does Springboot integrate the pagehelper paging function?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template