mybatis-plus 3.5分頁插件配置
前提
1.項(xiàng)目不是springboot, 是以前的常規(guī)spring項(xiàng)目
2.mp 從3.2升級到3.5,升級后發(fā)現(xiàn)原本的分頁竟然不起作用了,每次查詢都是查出所有
前后配置對比
jar包對比
jsqlparser我這里單獨(dú)引了包,因?yàn)榘姹咎筒荒苁褂脝幔@個(gè)依賴直接刪除了,因?yàn)閙p中本身自己就有這個(gè)jar包
以前的配置
現(xiàn)在的配置
官網(wǎng)介紹
官網(wǎng)地址
https://baomidou.com/pages/2976a3/#spring
<bean id="sqlSessionFactory" class="com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean">
<!-- 其他屬性 略 -->
<property name="configuration" ref="configuration"/>
<property name="plugins">
<array>
<ref bean="mybatisPlusInterceptor"/>
</array>
</property>
</bean>
<bean id="mybatisPlusInterceptor" class="com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor">
<property name="interceptors">
<list>
<ref bean="paginationInnerInterceptor"/>
</list>
</property>
</bean>
<bean id="paginationInnerInterceptor" class="com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor">
<!-- 對于單一數(shù)據(jù)庫類型來說,都建議配置該值,避免每次分頁都去抓取數(shù)據(jù)庫類型 -->
<constructor-arg name="dbType" value="H2"/>
</bean>
可以看到解決的方案就是增加了PaginationInnerInterceptor,然后增加dbtype
springboot 配置
@Configuration
@MapperScan("scan.your.mapper.package")
public class MybatisPlusConfig {
/**
* 添加分頁插件
*/
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.H2));
return interceptor;
}
}
最后
以上就是mp升級3.5后分頁不起作用的介紹文章來源:http://www.zghlxwxcb.cn/news/detail-776295.html
升級的時(shí)候因?yàn)轫?xiàng)目的原因會遇到很多其他問題,具體問題具體分析,有需要幫助的小伙伴可以留言文章來源地址http://www.zghlxwxcb.cn/news/detail-776295.html
到了這里,關(guān)于最新-mybatis-plus 3.5分頁插件配置的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!