问题描述:使用mybatis插件遇到的问题:版本5.0和4.2之前的区别:java.lang.ClassCastException: com.github.pagehelper.PageHelper cannot be cast to org.apache.ibatis.plugin.Interceptor
原因分析:
5版本:public class PageHelper extends PageMethod implements Dialect, Chain
在配置和新配置文件时:
<plugins>
<plugin interceptor="com.github.pagehelper.PageInterceptor">
</plugin>
</plugins>
4.2版本前:public class PageHelper implements Interceptor
<plugins>
<plugin interceptor="com.github.pagehelper.PageHelper">
<property name="dialect" value="mysql"/>
</plugin>
</plugins>
但是注意:4.2.x 注意这里面配置的jsqlparser版本和pagehelper版本的问题:
net.sf.jsqlparser.statement.select.PlainSelect.getGroupBy()Lnet/sf/jsqlparse
解决方案
修改pom 文件的版本即可:
pom.xml文件的坐标:
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.2.0</version>
</dependency>
<!--支持的坐标 JSqlParser解析SQL语句并将其转换为Java类的层次结构。可以使用Visitor模式导航生成的层次结构。-->
<dependency>
<groupId>com.github.jsqlparser</groupId>
<artifactId>jsqlparser</artifactId>
<version>3.1</version>
</dependency>
我的核心配置文件:
<!--分页插件助手 在mapper标签之前-->
<plugins>
<plugin interceptor="com.github.pagehelper.PageInterceptor">
</plugin>
</plugins>
我使用的这样测试通过!Over