最新-mybatis-plus 3.5分页插件配置

mybatis-plus 3.5分页插件配置

前提

1.项目不是springboot, 是以前的常规spring项目

2.mp 从3.2升级到3.5,升级后发现原本的分页竟然不起作用了,每次查询都是查出所有

前后配置对比

jar包对比

jsqlparser我这里单独引了包,因为版本太低不能使用吗,这个依赖直接删除了,因为mp中本身自己就有这个jar包

以前的配置

现在的配置

官网介绍

官网地址

https://baomidou.com/pages/2976a3/#spring

xml 复制代码
<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">
    <!-- 对于单一数据库类型来说,都建议配置该值,避免每次分页都去抓取数据库类型 -->
    <constructor-arg name="dbType" value="H2"/>
</bean>

可以看到解决的方案就是增加了PaginationInnerInterceptor,然后增加dbtype

springboot 配置

java 复制代码
@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后分页不起作用的介绍

升级的时候因为项目的原因会遇到很多其他问题,具体问题具体分析,有需要帮助的小伙伴可以留言

相关推荐
爱学英语的程序员2 小时前
面试官:你了解过哪些数据库?
java·数据库·spring boot·sql·mysql·mybatis
阿杰真不会敲代码6 小时前
Mybatis-plus入门到精通
java·tomcat·mybatis
侠客行031713 小时前
Mybatis连接池实现及池化模式
java·mybatis·源码阅读
老毛肚15 小时前
MyBatis体系结构与工作原理 上篇
java·mybatis
独断万古他化1 天前
【SSM开发实战:博客系统】(三)核心业务功能开发与安全加密实现
spring boot·spring·mybatis·博客系统·加密
fengxin_rou1 天前
[Redis从零到精通|第四篇]:缓存穿透、雪崩、击穿
java·redis·缓存·mybatis·idea·多线程
老毛肚2 天前
MyBatis插件原理及Spring集成
java·spring·mybatis
马尔代夫哈哈哈2 天前
MyBatis 入门与实战:从配置到CRUD一站式指南
mybatis
Jul1en_2 天前
【MyBatis/plus】核心配置、插件与 MyBatis-Plus 构造器 Wrapper
mybatis
LiZhen7982 天前
SpringBoot 实现动态切换数据源
java·spring boot·mybatis