Personal blog address :https://alexaccele.github.io/
PageHelper yes Mybatis A good paging plug-in for , But to use its paging function, you need to pay attention to a few points
1. Import related packages , for example maven Import dependence
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.4</version>
</dependency>
2. stay mybatis-config.xml Add plug-in to
<plugins>
<plugin interceptor="com.github.pagehelper.PageInterceptor">
<!-- Rationalize paging parameters -->
<property name="reasonable" value="true"/>
</plugin>
</plugins>
3. stay Controller The methods of
PageHelper.startPage(1,5);// Start with the first page , each page 5 Bar record
The above code should be followed by the query statement
List<Test> tests = testService.getAllTestsByTypeId(testTypeid);
PageInfo pageInfo = new PageInfo(tests,5);
When there are multiple query statements in a method , Only follow closely PageHelper.starPage() The query results will be paged after the method .
Lack of the above three steps will lead to page invalidation