Mybatis-plus的selectPage()分頁查詢不生效問題解決
背景:
項目需要從mybits切換到mubits-plus,但是我在進行分頁查詢的時候,發(fā)現(xiàn)一直不生效
問題原因:
添加監(jiān)聽器,配置如下:
@Configuration
@MapperScan("com.baomidou.mybatisplus.samples.deluxe.mapper")
public class MybatisPlusConfig {
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
return interceptor;
}
/**
* 自定義 SqlInjector
* 里面包含自定義的全局方法
*/
@Bean
public MyLogicSqlInjector myLogicSqlInjector() {
return new MyLogicSqlInjector();
}
}問題定位過程:
如果不感興趣著,可以在上面復制答案,直接操作就行
debug看看啥原因:
入參:
debug看沒有問題


結果:
兩條數(shù)據同時沒有總數(shù),不符合要求

看日志:
沒有拼接分頁查詢的動作

那么什么原因的
1.查看官網文檔
網管地址:MyBatis-Plus
官網有些水,沒看到具體信息
2.查看案例
github地址
GitHub - baomidou/mybatis-plus-samples: MyBatis-Plus Samples
在案例中找到了錯誤原因:
需要配置監(jiān)聽器
按照下面的方式添加就行
@Configuration
@MapperScan("com.baomidou.mybatisplus.samples.deluxe.mapper")
public class MybatisPlusConfig {
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
return interceptor;
}
/**
* 自定義 SqlInjector
* 里面包含自定義的全局方法
*/
@Bean
public MyLogicSqlInjector myLogicSqlInjector() {
return new MyLogicSqlInjector();
}
}到此這篇關于Mybatis-plus的selectPage()分頁查詢不生效問題解決的文章就介紹到這了,更多相關Mybatis-plus selectPage()分頁內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
重試框架Guava-Retry和spring-Retry的使用示例
spring-retry 和 guava-retry 工具都是線程安全的重試,能夠支持并發(fā)業(yè)務場景的重試邏輯正確性,本文主要介紹了重試框架Guava-Retry和spring-Retry的使用示例,感興趣的可以一下2023-09-09
如何使用IDEA開發(fā)Spark SQL程序(一文搞懂)
Spark SQL 是一個用來處理結構化數(shù)據的spark組件。它提供了一個叫做DataFrames的可編程抽象數(shù)據模型,并且可被視為一個分布式的SQL查詢引擎。這篇文章主要介紹了如何使用IDEA開發(fā)Spark SQL程序(一文搞懂),需要的朋友可以參考下2021-08-08
SpringBoot 整合 Avro 與 Kafka的詳細過程
本文介紹了如何在Spring Boot中使用Avro和Kafka進行數(shù)據的序列化和反序列化,并通過MyBatisPlus將數(shù)據存入數(shù)據庫,感興趣的朋友跟隨小編一起看看吧2024-12-12
SpringMVC 向jsp頁面?zhèn)鬟f數(shù)據庫讀取到的值方法
下面小編就為大家分享一篇SpringMVC 向jsp頁面?zhèn)鬟f數(shù)據庫讀取到的值方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-03-03

