一早搭建项目,发现这个分页插件一直出错,查了下资料发现,新版本有一点不一样。
com.github.pagehelper.PageHelper cannot be cast to org.apache.ibatis.plugin.Interceptor
pom引入
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.2.0</version>
</dependency>
然后mybatis配置文件,新版的
<!-- 配置分页插件 -->
<plugins>
<plugin interceptor="com.github.pagehelper.PageInterceptor">
<!-- 设置数据库类型 Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL六种数据库-->
<property name="helperDialect" value="mysql"/>
</plugin>
</plugins>
旧版的预计是5.0一下的
<plugins>
<plugin interceptor="com.github.pagehelper.PageHelper">
<!-- 配置数据库的方言 -->
<!-- 设置数据库类型 Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL六种数据库-->
<property name="dialect" value="mysql"/>
</plugin>
</plugins>
查询前使用
PageHelper.startPage(1, 2);
OK记录一下以防忘记了