This article shares the specific code displayed by Springboot integrated pagehelper pagination for your reference. The specific content is as follows
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>
2. Use
Many articles on the Internet say that they need to configure it in application.properties
Actually, there is no need at all, the default settings already meet most of the needs
Just 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);}PageHelper.startPage (how many pages to be displayed, the number of pages to be displayed);
The next line follows the query statement immediately. You cannot write anything else, otherwise it will have no effect.
PageHelper.startPage(apps.getPageNum(), apps.getPageSize());ArrayList<Apps> appsList = appsService.getApps(apps);
This only has the effect of pagination, and there is no detailed information about the total number of pages and other things
If you have a requirement for the number of pages, you need to add the following line
PageInfo<T> appsPageInfo = new PageInfo<>(appsList);
This meets all paging requirements
The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.