• 周四. 10 月 3rd, 2024

5G编程聚合网

5G时代下一个聚合的编程学习网

热门标签

Causes of paging failure of PageHelper, a pagination plug-in of mybatis

King Wang

1 月 3, 2022

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

发表回复