SpringBoot集成MybatisPlus使用PageHelper分页失效_lifan5757的博客-CSDN博客 老版本的 3.4.1不合用

很多同志不想用MybatisPlus自带的分页希望用PageHelper结果失效了

原因解决方案

1.可能是Jar冲突了,pom.xml文件只需要引入以下

<!--pagehelper 在version 下面添加 exclusions依赖(排除) 因为mybatisPlus中包含了-->
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>1.2.3</version>
            <exclusions>
             <exclusion>
             <groupId>org.mybatis</groupId>
             <artifactId>mybatis</artifactId>
             </exclusion>
            </exclusions>
        </dependency>

2.引入的包是这两个

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

3.MybatisPlus配置类

package com.lifan.config;

import java.util.Properties;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import com.baomidou.mybatisplus.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.plugins.PerformanceInterceptor;
import com.github.pagehelper.PageHelper;
/**
 * 
 * @author:Qizai
 *
 * @createTime:2020年2月18日下午3:24:48
 */
@EnableTransactionManagement
@Configuration
@MapperScan("com.lifan.dao*")
public class MybatisPlusConfig {
    
    /解决失效冲突/
    @Bean
    public PageHelper pageHelper() {
       PageHelper pageHelper = new PageHelper();
       Properties p = new Properties();
       p.setProperty("offsetAsPageNum", "true");
       p.setProperty("rowBoundsWithCount", "true");
       p.setProperty("reasonable", "true");
       pageHelper.setProperties(p);
       return pageHelper;
    }

    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }
    
    @Bean
    public PerformanceInterceptor performanceInterceptor(){
        return new PerformanceInterceptor();
    }
    
}


原网址: 访问
创建于: 2021-08-16 14:50:35
目录: default
标签: 无

请先后发表评论
  • 最新评论
  • 总共0条评论