MyBatisPlus 暫時分頁失效原因及問題解決
背景介紹
在更新完MybatisPlus版本后暫時分頁功能失效。
記得原來版本是可以成功的,可以在傳參時候將pageSize設置<0可以成功的暫時不分頁,結果升級完MybatisPlus版本后失效了,將pageSize<0的值拼接到了limit條件中,直接導致報錯。在一步一步的排查中發(fā)現(xiàn)是源碼中作了調整,-_-||
具體原因如下:
配置
分頁插件正確的配置應該如下
public PaginationInnerInterceptor paginationInnerInterceptor()
{
PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();
// 設置數(shù)據(jù)庫類型為mysql
paginationInnerInterceptor.setDbType(DbType.MYSQL);
// 設置最大單頁限制數(shù)量,默認 500 條,-1 不受限制
// 在mybatis-plus-boot-starter 3.4.3.1及以后需要注釋掉才能在設置pageSize<0時候成功暫時不分頁
// paginationInnerInterceptor.setMaxLimit(-1L);
return paginationInnerInterceptor;
}源碼分析
3.4.3以及以前的版本
在 PaginationInnerInterceptor 中的 beforeQuery 方法
public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException {
......
// 此處只有判斷pageSize的值,只要小于0就可以暫時不分頁
if (page.getSize() < 0L) {
if (addOrdered) {
PluginUtils.mpBoundSql(boundSql).sql(buildSql);
}
} else {
......
}
}3.4.3.1及以后版本
在 PaginationInnerInterceptor 中的 beforeQuery 方法
public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) {
......
// size 小于 0 且不限制返回值則不構造分頁sql
Long _limit = page.maxLimit() != null ? page.maxLimit() : maxLimit;
if (page.getSize() < 0 && null == _limit) {
if (addOrdered) {
PluginUtils.mpBoundSql(boundSql).sql(buildSql);
}
return;
}
......
}可以看出在3.4.3.1及以后判斷條件多了一個限制,就是不能設置單頁最大限制(maxLimit)屬性值, 只有該值為null的前提下設置pageSize<0才能暫時不分頁成功?。?!
到此這篇關于MyBatisPlus 暫時分頁失效原因及問題解決的文章就介紹到這了,更多相關MyBatisPlus 暫時分頁失效內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
MyBatis中模糊查詢使用CONCAT('%',#{str},'%')出錯的解
這篇文章主要介紹了MyBatis中模糊查詢使用CONCAT('%',#{str},'%')出錯的解決,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-01-01
java+vue3+el-tree實現(xiàn)樹形結構操作代碼
基于springboot + vue3 elementPlus實現(xiàn)樹形結構數(shù)據(jù)的添加、刪除和頁面展示,本文通過示例代碼給大家介紹的非常詳細,感興趣的朋友跟隨小編一起看看吧2024-06-06
IDEA使用JDBC導入配置jar包連接MySQL數(shù)據(jù)庫
這篇文章介紹了IDEA使用JDBC安裝配置jar包連接MySQL數(shù)據(jù)庫的方法,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2022-12-12
springboot項目中使用docker進行遠程部署的實現(xiàn)
本文主要介紹了在Spring Boot項目中使用Docker進行遠程部署,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2025-01-01
SpringMVC源碼解讀之 HandlerMapping - AbstractDetectingUrlHandlerM
這篇文章主要介紹了SpringMVC源碼解讀之 HandlerMapping - AbstractDetectingUrlHandlerMapping系列初始化的相關資料,需要的朋友可以參考下2016-02-02

