使用PageHelper分页助手时报如下异常:
Caused by: java.lang.ClassCastException: com.github.pagehelper.PageHelper cannot be cast to org.apache.ibatis.plugin.Interceptor
导入的依赖
<dependency>
<groupId>com.github.jsqlparser</groupId>
<artifactId>jsqlparser</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.2</version>
<scope>test</scope>
</dependency>
Mybatis核心配置文件
<!--配置分页助手插件-->
<plugins>
<!--<plugin interceptor="com.github.pagehelper.PageInterceptor">-->
<plugin interceptor="com.github.pagehelper.PageHelper">
<property name="dialect" value="mysql"/>
</plugin>
</plugins>
百度后知道:5.0之前的版本使用以上的配置
5.0之后的版本使用如下配置。。。
5.0之后Mybatis核心配置文件
<!--配置分页助手插件-->
<plugins>
<plugin interceptor="com.github.pagehelper.PageInterceptor">
<property name="dialect" value="mysql"/>
</plugin>
</plugins>
之后又报错
Caused by: java.lang.ClassNotFoundException: mysql
百度后知道:
自4.0.0以后的版本以后默认的数据库为mysql,如果是其他数据库需要指定方言,所以不需要我们再去指定数据库
原来PageHelper5.0版本pagehelper是继承了PageMethod和实现了Dialect,PageInterceptor是实现了Interceptor接口
参考:添加链接描述
<!--配置分页助手插件-->
<plugins>
<plugin interceptor="com.github.pagehelper.PageInterceptor"></plugin>
</plugins>
最终问题解决!!!