MyBatis分页插件版本问题
Cause: java.lang.ClassCastException: com.github.pagehelper.PageHelper cannot be cast to org.apache.ibatis.plugin.Interceptor
一、5.0以下版本分页插件的xml配置文件
<configuration>
<plugins>
<plugin interceptor="com.github.pagehelper.PageHelper">
<!-- 告诉分页插件是哪个数据库 -->
<property name="dialect" value="mysql"/>
</plugin>
</plugins>
</configuration>
在5.0版本以下xml配置文件中需要配置数据库名
二 、5.0以上版本分页插件的xml配置文件
<configuration>
<plugins>
<plugin interceptor="com.github.pagehelper.PageInterceptor"></plugin>
</plugins>
</configuration>
在5.0版本以上xml配置文件中是不需要配置数据库名
三、配置错误时的运行截图
异常信息
异常关键信息:
分页插件的Interceptor接口没有被实现,进行源码查看,源码截图如下:
只需要在分页插件配置文件中配置这个类即可,无需指定数据库
四、总结
_ 出现这个问题的原因是自己没有注意使用插件的版本问题,用老版本的配置模式来匹配新版本的插件,以后在使用时首先要了解新版本类容再使用,随时学习并时刻更新自己的技能。_