maven repositary, the paging component commonly used two
com.github.pagehelper » pagehelper-spring-boot-starter
com.github.pagehelper » pagehelper
Lay a lot of pits, a record of the way to be successful:
=============================== dividing line ================= =======
1. introduced in pom.xml Dependence: Selection 4.2.x version pagehelper of (5.1.2 If the election, I do not know how to configure, the Internet did not find)
<dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>4.2.1</version> </dependency>
2. Configure class, which is 4.xx version of the wording, if it is 5.1.2, you can not write like below (no effect)
package com.yggdrasill.framework; import com.github.pagehelper.PageHelper; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import java.util.Properties; @Configuration public class PageMybatisConf { @Bean public PageHelper pageHelper() { System.out.println("MyBatisConfiguration.pageHelper()"); PageHelper pageHelper = new PageHelper(); Properties p = new Properties(); p.setProperty("offsetAsPageNum", "true"); p.setProperty("rowBoundsWithCount", "true"); p.setProperty("reasonable", "true"); p.setProperty("dialect","postgresql"); pageHelper.setProperties(p); return pageHelper; } }
3. calling code
public PageInfo <the Slave> queryApiSlaveList (Pager <the Slave> Page) {
// PageHelper.startPage (Page, the pageSize); plug open tab, on the top to help generate the query statement tab
PageHelper.startPage (page.getPage (), page. getPageSize ()); // 1,10
List <the Slave> listSlave = slaveMapper.selectAll ();
// data after encapsulation tab back to the client to do show some PageInfo package as a class
PageInfo <the Slave> = pageInfoUser new new PageInfo <the Slave> (listSlave);
return pageInfoUser;
}
Results shown in Figure
carry out! ! !
===================================================================
ps: do not have to configure a few parameters in application.properties, and if it is into pagehelper-spring-boot-starter, you need to configure
pagehelper.helperDialect=postgresql
pagehelper.reasonable=true
pagehelper.supportMethodsArguments=true
pagehelper.params=count=countSql
pagehelper.page-size-zero=true
As pagehelper-spring-boot-starter embodiment, may refer to https://blog.csdn.net/csdn_huzeliang/article/details/79350425