美文网首页
mybatis配置pagehelper分页插件

mybatis配置pagehelper分页插件

作者: Restart白蓝 | 来源:发表于2020-12-26 18:36 被阅读0次

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

    相关文章

      网友评论

          本文标题:mybatis配置pagehelper分页插件

          本文链接:https://www.haomeiwen.com/subject/upbgnktx.html