SpringBoot集成MybatisPlus使用PageHelper分页失效

很多同志不想用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;

impo

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring Boot使用Mybatis-Plus进行分页配置,需要进行以下步骤: 1. 在pom.xml文件中添加Mybatis-Plus和MySQL依赖: ``` <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>[2]</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> ``` 2. 在application.properties文件中配置数据库连接信息。 3. 创建一个自定义的配置类,并使用`@Configuration`和`@MapperScan`注解进行配置: ```java @Configuration @MapperScan("com.demo.mapper") // 指定Mapper所在的包路径 public class CustomMyBatisPlusConfig { @Bean public MybatisPlusInterceptor mybatisPlusInterceptor() { MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); interceptor.addInnerInterceptor(paginationInnerInterceptor()); return interceptor; } @Bean public PaginationInnerInterceptor paginationInnerInterceptor() { PaginationInnerInterceptor page = new PaginationInnerInterceptor(); page.setDbType(DbType.MYSQL); // 设置数据库类型 return page; } } ``` 这里的配置类中使用`MybatisPlusInterceptor`和`PaginationInnerInterceptor`来实现分页拦截器的配置,其中`PaginationInnerInterceptor`是Mybatis-Plus自带的分页插件,并通过`setDbType(DbType.MYSQL)`方法设置数据库类型为MySQL。 通过以上配置,你就可以在Spring Boot使用Mybatis-Plus进行分页查询了。<span class="em">1</span><span class="em">2</span><span class="em">3</span><span class="em">4</span>

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值