Mybatis分页插件PageHelper (1.2.*) 踩坑

I have to remind myself that some birds aren't meant to be caged. Their feathers are just too bright. And when they fly away, the part of you that knows it was a sin to lock hem up DOES rejoice. Still, the place you live in is that much more drab and empty that they're gone. I guess I just miss my friend.

最近项目升级,Mybatis和PageHelper都采用较新版本,然而出现了一些版本不匹配的问题,现将问题总结如下:

问题一

项目中使用该配置:

<dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactId>pagehelper-spring-boot-starter</artifactId>
    <version>1.2.10</version>
    <exclusions>
        <exclusion>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
        </exclusion>
    </exclusions>
</dependency>

<dependency>
    <groupId>tk.mybatis</groupId>
    <artifactId>mapper-spring-boot-starter</artifactId>
    <version>2.1.5</version>
</dependency>
@Configuration
@ConditionalOnBean({SqlSessionFactory.class})
@EnableConfigurationProperties({PageHelperProperties.class})
@AutoConfigureAfter({MybatisAutoConfiguration.class})
public class PageHelperAutoConfiguration {
    @Autowired
    private List<SqlSessionFactory> sqlSessionFactoryList;
    @Autowired
    private PageHelperProperties properties;

    public PageHelperAutoConfiguration() {
    }

由于PageHelper中包含配置类PagehelperAutoConfiguration,需要MybatisAutoConfiguration,而上述mybatis版本并不包含该类,因此降级为1.1.7

<dependency>
    <groupId>tk.mybatis</groupId>
    <artifactId>mapper-spring-boot-starter</artifactId>
    <version>1.1.7</version>
</dependency>

该依赖中包含MybatisAutoConfiguration,问题解决。

问题二

然而,项目启动中又出现问题:

nested exception is org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: com.github.pagehelper.PageException:java.lang.ClassNotFoundException: mysql

查询发现是新版pagehelper配置发生变化的问题,
旧版配置分页插件数据库:pagehelper.dialect: mysql (该配置请去掉
新版则是 pagehelper.helper-dialect: mysql (由于支持自动检测当前的数据库链接,该配置不需要
问题解决。

参考资料:https://icharle.com/mybatispagehelper.html

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 在实际的项目开发中,常常需要使用到分页,分页方式分为两种:前端分页和后端分页。 前端分页一次ajax请求数据的所有...
    意识流丶阅读 70,504评论 2 70
  • 1. 简介 1.1 什么是 MyBatis ? MyBatis 是支持定制化 SQL、存储过程以及高级映射的优秀的...
    笨鸟慢飞阅读 5,866评论 0 4
  • Mybatis分页插件-PageHepler的使用 使用方法 1. 引入分页插件 引入分页插件一共有下面2种方式,...
    匆匆岁月阅读 1,456评论 0 7
  • feisky云计算、虚拟化与Linux技术笔记posts - 1014, comments - 298, trac...
    不排版阅读 3,955评论 0 5
  • 对于使用Mybatis时,最头痛的就是写分页,需要先写一个查询count的select语句,然后再写一个真正分页查...
    Apple_Boy阅读 812评论 1 2