Common reasons why SpringBoot Integration PageHelper Pagination Invalid
Dependency issues
This reason is related to the paging dependencies introduced in the file
Since springboot itself integrates the pagerhelper paging plugin
Just introduce the following dependencies
<!-- spring-boot mybatis pagehelper --> <dependency> <groupId></groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.2.10</version> </dependency>
If the imported dependencies are as follows
Need to add Bean injection (please use Baidu on how to add it)
<dependency> <groupId></groupId> <artifactId>pagehelper</artifactId> <version>5.1.10</version> </dependency>
2. Execute (int pageNum, int pageSize)
After that, the page query was not followed, but the other query was executed first.
After initializing the pager as follows, the page query statement of mybatis should be followed. If there are other query requirements in the method, the (int pageNum, int pageSize) method needs to be executed after the other query is completed.
public PageInfo<R> page(Map<String, ? extends Object> map) { //Get page 1, 10 items, default query total count count ((("pageNum").toString()), (("pageSize").toString())); String sql = ("%s%s",sqlMapping , ("mapping")==null?"getPageObjList" : ("mapping")) ; List<R> l = (sql , map); return new PageInfo<R>(l); }
3. Mybatis' pagination interceptor is not configured (and the problem I encountered)
When the interceptor is not configured, all result data will be returned every time a List query is performed. At this time, the interceptor class needs to be injected into the startup class
@Bean public Interceptor[] plugins() { return new Interceptor[]{new PageInterceptor()}; }
Or add the following code to the MyBatis configuration file
<configuration> <plugins> <plugin interceptor=""/> </plugins> </configuration>
Summarize
The above is a common problem and solution that everyone encounters on the Internet when springboot uses pagehelper to paginate, and encounters all data but does not paginate.
These are just personal experience. I hope you can give me a reference and I hope you can support me more.