PageHelper will return data after pagination exceeds the maximum number of pages

Problem Description:

In the microservices, the query interface is used, and pageHelper is used. The database only has 8 rows of data. The problem is here:

pageNum=1&pageSize=10, the returned data is those 8 pieces of data;

pageNum=2&pageSize=10, pageNum=3&pageSize=10, etc...It will still return data!!!

the reason:

This is a feature that comes with pageHelper, which is called reasonable paging parameter rationalization. It is available for version 3.3.0 and above, and the default is false. When rationalization is enabled, the first page will be queried if pageNum<1, and the last page will be queried if pageNum>pages; when rationalization is disabled, empty data will be returned if pageNum<1 or pageNum>pages is disabled.

solve:

Join in the general project <property name="reasonable" value="true" />,

Inside the Spring Boot project:pagehelper.reasonable=true  当为false的时候,如果当前页超过最大页数后,就不会返回数据,当为true的时候,当前页超过最大页数后,会返回最后一页的数据

# PageHelper分页插件
pagehelper:
  helperDialect: mysql
  reasonable: false
  supportMethodsArguments: true
  params: count=countSql

Summary: Whether it is true or false, you can set it according to your own business scenario. If you exceed the maximum page, set it to true if you need to return data, and set it to false if you don't need to return data.

Guess you like

Origin blog.csdn.net/Tom_sensen/article/details/115327434