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

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

相关推荐
不平衡的叉叉树3 小时前
mybatis-plus的insertBatchSomeColumn方法实现批量插入
java·mybatis
最好结果17 小时前
MyBatis 精确查询逗号分隔字符串
mysql·mybatis·1024程序员节
信仰_2739932431 天前
Mybatis一级缓存
java·缓存·mybatis
lunz_fly19922 天前
【源码解读之 Mybatis】【核心篇】--第7篇:ParameterHandler参数处理机制
mybatis
lunzi_fly2 天前
【源码解读之 Mybatis】【核心篇】--第7篇:ParameterHandler参数处理机制
mybatis
2401_837088502 天前
JedisConnectionFactory 连接池工厂类
mybatis
计算机学姐2 天前
基于微信小程序的高校班务管理系统【2026最新】
java·vue.js·spring boot·mysql·微信小程序·小程序·mybatis
梁辰兴3 天前
企业培训笔记:外卖平台后端--套餐管理模块--新建套餐信息
笔记·vue·mybatis·springboot·外卖管理系统
信仰_2739932433 天前
Mybatis-Spring重要组件介绍
java·spring·mybatis
通往曙光的路上3 天前
接口练习哈哈
mybatis