MyBatis分页插件pagehelper和PageInterceptor版本问题——源码分析

MyBatis分页插件版本问题

Cause: java.lang.ClassCastException: com.github.pagehelper.PageHelper cannot be cast to org.apache.ibatis.plugin.Interceptor

问题背景:

在某商城的学习过程中用到的分页插件的版本是4.0以下的版本,基本不支持多边查询的分页,学习资料中是经过高手重新编写的,后来查资料发现最新的5.0及以上的版本已经有了解决方案,便直接用了5.0的版本,除了引用这个pagehelper-x.x.x.jar 和其依赖包 jsqlparser-0.9.5.jar,开始的配置就照着原来的配置在SqlMapConfig.xml进行了配置

一、5.0以下版本分页插件的xml配置文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
    <plugins>
        <!-- com.github.pagehelper 为 PageHelper 类所在包名 -->
        <plugin interceptor="com.github.pagehelper.PageHelper">
            <!-- 设置数据库类型 Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL 六种数据库-->
            <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配置文件中是不需要配置数据库名

三、配置错误时的运行错误日志

一月 09, 2021 10:31:01 下午 org.apache.catalina.core.StandardContext listenerStart
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in URL [jar:file:/E:/apache-maven-3.6.3-bin/m2/com/pinyougou/pinyougou-dao/1.0-SNAPSHOT/pinyougou-dao-1.0-SNAPSHOT.jar!/spring/applicationContext-dao.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse config resource: class path resource [mybatis/SqlMapConfig.xml];
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值