问题描述
在springboot和mybatis中使用分页插件时报错:java.lang.ClassCastException: class java.util.ArrayList cannot be cast to class com.github.pagehelper.Page (java.util.ArrayList is in module java.base of loader 'bootstrap'; com.github.pagehelper.Page is in unnamed module of loader 'app') 试了很多方法都没有解决
原因分析:
实际上只是引入的pagehelper版本低了,和项目中使用的其他库的版本不兼容。版本不匹配导致了类型转换错误。
解决方案:
在pom.xml文件中将引入的pagehelper依赖的版本更新为1.4.7即可,以下是分页插件的依赖,直接将其复制粘贴到pom.xml文件中,刷新。若刷新失败就重启一下idea,再次打开后会自动下载更新版本(注:我用的Java版本为17,JDK20,springboot版本是3.x.x)
<!-- 分页插件 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.4.7</version>
</dependency>