MybatisPlus分頁失效不起作用的解決
【問題描述】
在使用MybatisPlus的selectPage時發(fā)現(xiàn)分頁不起作用,每次返回的都是全部的數(shù)據(jù),同時getPages()和getTotal()返回的都是0。
【相關(guān)代碼】
mybatisPlus的版本:
<dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.5.1</version> </dependency>
selectPage操作的示例代碼:
IPage<UserBuyCarsDao> userBuyCarsDaoPage = userBuyCarsMapper.selectPage(new Page<>(currentPage, pageSize), new LambdaQueryWrapper<UserBuyCarsDao>() .eq(UserBuyCarsDao::getUserCode, userCode) .eq(UserBuyCarsDao::getIsDelete, 0));
其中UserBugCarsDao和userBugCarsMapper都定義完整,不會存在問題。
如果使用分頁操作是需要添加攔截器的,config代碼如下:
@Configuration @MapperScan(basePackages = {"com.core.mapper"}) public class MybatisPlusConfig { /** * 新的分頁插件,一緩和二緩遵循mybatis的規(guī)則,需要設(shè)置 MybatisConfiguration#useDeprecatedExecutor = false 避免緩存出現(xiàn)問題(該屬性會在舊插件移除后一同移除) */ @Bean public MybatisPlusInterceptor mybatisPlusInterceptor() { MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); return interceptor; } @Bean public PaginationInnerInterceptor paginationInnerInterceptor() { PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(); paginationInnerInterceptor.setOverflow(false); return paginationInnerInterceptor; } }
【問題定位】
初步懷疑是攔截器沒有生效,為了驗證這一點,在mybatisPlusInterceptor()函數(shù)中打一個斷點。執(zhí)行測試程序,發(fā)現(xiàn)確實沒有進入這個函數(shù)。
為什么MybatisPlusInterceptor這個bean注冊不成功?是不是啟動程序沒有掃描到這個@Configuration標記。
查看springboot的啟動類,發(fā)現(xiàn)確實沒有掃描到這個包文件。
【問題修復(fù)】
在springboot啟動類中增加掃描config文件的路徑,示例如下:
然后再執(zhí)行debug,發(fā)現(xiàn)可以進入mybatisPlusInterceptor的斷點。
到此這篇關(guān)于MybatisPlus分頁失效不起作用的解決的文章就介紹到這了,更多相關(guān)MybatisPlus分頁失效內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Apache?Commons?BeanUtils:?JavaBean操作方法
這篇文章主要介紹了Apache?Commons?BeanUtils:?JavaBean操作的藝術(shù),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-12-12springboot 加載 META-INF/spring.factories方式
這篇文章主要介紹了springboot 加載 META-INF/spring.factories方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-10-10springboot整合websocket最基礎(chǔ)入門使用教程詳解
這篇文章主要介紹了springboot整合websocket最基礎(chǔ)入門使用教程詳解,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-03-03解決Spring JPA 使用@transaction注解時產(chǎn)生CGLIB代理沖突問題
這篇文章主要介紹了解決Spring JPA 使用@transaction注解時產(chǎn)生CGLIB代理沖突問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-08-08