目录
一、问题描述
1.MyBatis使用PageHelper进行分页,提示以下错误
2.maven依赖
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.6</version>
</dependency>
3.插件配置
<plugin interceptor="com.github.pagehelper.PageHelper"/>
二、问题原因
引入的版本和和配置的插件不匹配,在PageHelper5版本中MyBatis的插件指定不为PageHelper
三、问题解决
1.将Maven依赖改为版本4
2.将插件配置改为<plugin interceptor="com.github.pagehelper.PageInterceptor"/>
3.对应关系
<plugins>
<!-- PageHelper4版本插件配置 -->
<plugin interceptor="com.github.pagehelper.PageHelper"/>
</plugins>
<!-- PageHelper4版本依赖 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>4.1.6</version>
</dependency
---------------------------------------------------------------------
<plugins>
<!-- PageHelper5版本配置 -->
<plugin interceptor="com.github.pagehelper.PageInterceptor"/>
</plugins>
<!-- PageHelper5版本依赖 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.6</version>
</dependency>
四、顺带问题
以上是问题引入高版本jar在MyBatis中配置的插件是低版本的,如果反过来配置了高版本插件引入低版本jar,则会出现以后错误
Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'com.github.pagehelper.PageInterceptor'. Cause: java.lang.ClassNotFoundException: Cannot find class: com.github.pagehelper.PageInterceptor