SpringBoot + PageHelper, MyBatis分頁不生效解決方案


PageHelper是Mybatis的一個很好的分頁插件,但要使用它的分頁功能需要注意一下幾點。

1.導入相關包,例如maven導入依賴

1 <dependency>
2     <groupId>com.github.pagehelper</groupId>
3     <artifactId>pagehelper</artifactId>
4     <version>5.1.4</version>
5 </dependency>

需要注意的是SpringBoot用的是pagehelper-spring-boot-starter.

1 <dependency>
2     <groupId>com.github.pagehelper</groupId>
3     <artifactId>pagehelper-spring-boot-starter</artifactId>
4     <version>1.2.3</version>
5 </dependency>

 

2.在mybatis-config.xml中添加插件

1 <plugins>
2    <plugin interceptor="com.github.pagehelper.PageInterceptor">
3         <!--分頁參數合理化  -->
4         <property name="reasonable" value="true"/>
5    </plugin>
6 </plugins>

SpringBoot yml配置文件配置方式

1 pagehelper: 2  helperDialect: mysql 3   reasonable: true #開啟優化,如果開啟優化,在分頁頁碼結果沒有數據的時候,會顯示有數據的頁碼數據 4   supportMethodsArguments: true #是否支持接口參數來傳遞分頁參數,默認false 5   pageSizeZero: false #pageSize=0 返回所有 6   params: count=countSql

 

PageHelper官網:https://pagehelper.github.io/docs


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM