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 configurehelperDialect
properties 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 valuefalse
, this parameterRowBounds
is valid when used as a paging parameter. When this parameter istrue
set to ,RowBounds
theoffset
parameter in willpageNum
be used as a pagination, and the two parameters of page number and page size can be used for paging. -
rowBoundsWithCount
: The default valuefalse
, this parameterRowBounds
is valid when used as a paging parameter. When this parameter istrue
set to ,RowBounds
count queries are made using pagination. -
pageSizeZero
: The default value isfalse
, when this parameter istrue
set to, ifpageSize=0
orRowBounds.limit = 0
all the results will be queried (equivalent to not executing the paging query, but the returned result is still thePage
type). -
reasonable
: Paging rationalization parameter, the default value isfalse
. When this parameter istrue
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 defaultfalse
, the query is performed directly based on the parameters. -
params
: In order to supportstartPage(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 configuredpageNum,pageSize,count,pageSizeZero,reasonable
. If the mapping is not configured, the default value is used. The default value ispageNum=pageNum;pageSize=pageSize;count=countSql;reasonable=reasonable;pageSizeZero=pageSizeZero
. -
supportMethodsArguments
: Supports passing paging parameters through Mapper interface parameters. By defaultfalse
, the paging plugin will automatically take values from the parameter values of the query method according toparams
the fields configured above, and will automatically paginate when a suitable value is found. The usage method can refer to the sumcom.github.pagehelper.test.basic
under the package in the test code .ArgumentsMapTest
ArgumentsObjTest
-
autoRuntimeDialect
: The default value isfalse
.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 supportedsqlserver2012
, only availablesqlserver
). -
closeConn
: The default value istrue
. When using the runtime dynamic data source or without settinghelperDialect
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 istrue
closed by default. After settingfalse
, the obtained connection will not be closed. The setting of this parameter depends on the data source you choose.