PageHelper-com.github.pagehelper.PageHelper cannot be cast to org.apache.ibatis.plugin.Interceptor

目录

一、问题描述

二、问题原因

三、问题解决

四、顺带问题


一、问题描述

    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

 

  • 19
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 13
    评论
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值