解決pagehelper分頁不生效

原來版本:

springboot1.5.2 + mybatis1.1.1 + pagehelper4.1.6 生效
(而且不需要額外其他配置)

        <!-- mybatis -->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.1.1</version>
        </dependency>
        
        <!-- pageHelper 分頁插件-->
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper</artifactId>
            <version>4.1.6</version>
        </dependency>

升級版本:

springboot2.1.4 + mybatis2.0.0 + pagehelper1.2.5 生效
(需要額外的配置,配置文件或配置類)

        <!-- mybatis -->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.0.0</version>
        </dependency>

        <!-- pageHelper 分頁插件,未生效-->
        <!-- <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper</artifactId>
            <version>5.1.2</version>
        </dependency> -->
        <!-- 分頁插件生效 -->
		<dependency>
			<groupId>com.github.pagehelper</groupId>
			<artifactId>pagehelper-spring-boot-starter</artifactId>
			<version>1.2.5</version>
		</dependency>

yml配置

##打印sql     
mybatis:
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl 
#分頁設置
pagehelper:
  helper-dialect: postgresql
  reasonable: true
  support-methods-arguments: true
  params: count=countsql

或者 application.yml 添加配置

##pageHelper分頁插件
pagehelper.helper-dialect=postgresql
pagehelper.reasonable=true
pagehelper.support-methods-arguments=true
pagehelper.params=count=countSql

測試是OK的
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章