最新-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后分页不起作用的介绍

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

相关推荐
耀耀_很无聊8 小时前
07_通过 Mybatis 自动填充记录的创建时间和更新时间
mybatis
程序员张39 小时前
SQL分析与打印-p6spy组件
spring boot·sql·mybatis·mybatisplus·p6spy
喜欢敲代码的程序员1 天前
SpringBoot+Mybatis+MySQL+Vue+ElementUI前后端分离版:项目搭建(一)
spring boot·mysql·elementui·vue·mybatis
一只猿Hou2 天前
java分页插件| MyBatis-Plus分页 vs PageHelper分页:全面对比与最佳实践
java·mybatis
java—大象11 天前
基于java SSM的房屋租赁系统设计和实现
java·开发语言·数据库·spring boot·layui·mybatis
Mutig_s11 天前
Spring Boot动态数据源切换:优雅实现多数据源管理
java·数据库·spring boot·后端·mybatis
编程乐学(Arfan开发工程师)12 天前
73、单元测试-断言机制
服务器·数据库·servlet·单元测试·sqlite·log4j·mybatis
小时候的阳光12 天前
MyBatis 的一级缓存导致的数据一致性问题分析
缓存·mybatis·事务·隔离级别
烙印60112 天前
MyBatis原理剖析(三)--加载配置文件
服务器·tomcat·mybatis