mybatisPlus 无法实现分页查询(实际没有进行分页查询,total始终为0)

文章讲述了在开发过程中遇到分页查询的total值始终为0的状况,解决方案是添加MybatisPlus的分页插件依赖,并在配置文件中设置PaginationInnerInterceptor,特别提到了需要与项目的MybatisPlus版本匹配,以避免运行时错误。按照提供的方法修改后,total变量能正确获取值。
摘要由CSDN通过智能技术生成

看控制台发现根本没进行分页查询 ,所以total的变量的值始终为0

解决:

添加maven依赖

        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-extension</artifactId>
            <version>3.4.2</version>
        </dependency>

这里使用的是3.4.2版本的,必须跟自己的mybatisplus版本对应,不然项目运行可能会报错。

复制以下代码

package com.jiang.demo.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MybatisPlusConfig {

    /**
     * 分页插件
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }

}

重新运行代码,发现total变量的值已经有了

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值