Why does pageHelper return data after exceeding the maximum number of pages

To make a query interface in the microservice , using pageHelper, the database has only 8 rows of data, pageNum=1&pageSize=10, pageNum=2&pageSize=10, pageNum=3&pageSize=10. . . The returned data are all those 8 items.

Reason: This is a function that comes with pageHelper, which is called reasonable paging parameter rationalization. It is available in versions 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.

Solution: add it in the general project <property name="reasonable" value="false" />, in the spring  Boot project:pagehelper.reasonable=false

 

Paging plugin parameters introduction: 

  • helperDialect: The paging plugin will automatically detect the current database link and automatically select the appropriate paging method. You can configure helperDialectproperties to specify which dialect the pagination plugin uses. When configuring, the following abbreviated values ​​can be used:

    oracle,mysql,mariadb,sqlite,hsqldb,postgresql,db2,sqlserver,informix,h2,sqlserver2012,derby

    Special attention: When using the SqlServer2012 database, you need to manually specify as  sqlserver2012, otherwise the paging will be performed using the SqlServer2005 method.

    You can also implement  AbstractHelperDialect, and then configure this property as the fully qualified name of the implementation class to use a custom implementation method.

  • offsetAsPageNum: The default value  false, this parameter  RowBounds is valid when used as a paging parameter. When this parameter is true set  to , RowBounds the  offset parameter  in will pageNum be used as a pagination, and the two parameters of page number and page size can be used for paging. 
  • rowBoundsWithCount: The default value false, this parameter  RowBounds is valid when used as a paging parameter. When this parameter is trueset  to , RowBounds count queries are made using pagination.
  • pageSizeZero: The default value is  false, when this parameter is true set  to, if pageSize=0 or  RowBounds.limit = 0 all the results will be queried (equivalent to not executing the paging query, but the returned result is still the  Page type).
  • reasonable: Paging rationalization parameter, the default value is false. When this parameter is true set to , pageNum<=0 the first page will be queried, pageNum>pages(when the total number is exceeded), the last page will be queried. By default false , the query is performed directly based on the parameters.
  • params: In order to support startPage(Object params)the method, this parameter is added to configure the parameter mapping, which is used to get the value from the object according to the property name. It can be configured  pageNum,pageSize,count,pageSizeZero,reasonable. If the mapping is not configured, the default value is used. The default value is pageNum=pageNum;pageSize=pageSize;count=countSql;reasonable=reasonable;pageSizeZero=pageSizeZero.
  • supportMethodsArguments: Supports passing paging parameters through Mapper interface parameters. By default false, the paging plugin will automatically take values ​​from the parameter values ​​of the query method according to  params the fields configured above, and will automatically paginate when a suitable value is found.  The usage method can refer to the sum  com.github.pagehelper.test.basic under the package  in the test code  .ArgumentsMapTestArgumentsObjTest
  • autoRuntimeDialect: The default value is  false. true When set  to , allows to automatically identify the pagination of the corresponding dialect based on multiple data sources at runtime (automatic selection is not supported sqlserver2012, only available sqlserver).
  • closeConn: The default value is  true. When using the runtime dynamic data source or without setting  helperDialect the property to automatically obtain the database type, a database connection will be automatically obtained. This property is used to set whether to close the obtained connection. It is trueclosed by default. After setting  false , the obtained connection will not be closed. The setting of this parameter depends on the data source you choose. 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326257256&siteId=291194637
Recommended