mybatis配置pagehelper分页插件

一早搭建项目,发现这个分页插件一直出错,查了下资料发现,新版本有一点不一样。
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记录一下以防忘记了

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。