springboot 下整合pagehelper yml方式

注意这篇文章只是讲怎么用,没有具体的解释,但是应该能让你跑起来

首先我们需要有一个已经可以运行的springboot 项目,具体怎么去配这里就不赘述了

导包

注意,springboot项目一定要导这个包

<dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>1.2.3</version>
        </dependency>

而且你的springboot版本得是2.5.5
我之前是2.6.1
在这里插入图片描述
然后就会报这个错误

Description:

The dependencies of some of the beans in the application context form a cycle:

┌──->──┐
|  com.github.pagehelper.autoconfigure.PageHelperAutoConfiguration
└──<-──┘


Action:

Relying upon circular references is discouraged and they are prohibited by default. Update your application to remove the dependency cycle between beans. As a last resort, it may be possible to break the cycle automatically by setting spring.main.allow-circular-references to true.

所以赶紧迷途知返,起码截止2021/12/26还是2.6.1还是不能用pagehelper
改成这个
在这里插入图片描述

yml的配置

pagehelper:
#  helperDialect: mysql #这里是我看的另外一种解决办法是把这个注掉,但是我试了后发现不行,如果你们用我的方法不成功,可以试试这个
  reasonable: true
  supportMethodsArguments: true
  params: count=countSql

总的yml配置

#开发环境
server:
  port: 8080
spring:
  application:
    name: SpringbootTestApplication
  datasource:
    url: jdbc:mysql://localhost:3306/mht?useUnicode=true&characterEncoding=utf8&useSSL=false
    username: root
    password: 123456
    driver-class-name: com.mysql.cj.jdbc.Driver
    druid:
      #2.连接池配置
      #初始化连接池的连接数量 大小,最小,最大
      initial-size: 5
      min-idle: 5
      max-active: 20
      #配置获取连接等待超时的时间
      max-wait: 60000
      #配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
      time-between-eviction-runs-millis: 60000
      # 配置一个连接在池中最小生存的时间,单位是毫秒
      min-evictable-idle-time-millis: 30000
      validation-query: SELECT 1 FROM DUAL
      test-while-idle: true
      test-on-borrow: true
      test-on-return: false
      # 是否缓存preparedStatement,也就是PSCache  官方建议MySQL下建议关闭   个人建议如果想用SQL防火墙 建议打开
      pool-prepared-statements: true
      max-pool-prepared-statement-per-connection-size: 20
      # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
      filter:
        stat:
          merge-sql: true
          slow-sql-millis: 5000
      #3.基础监控配置
      web-stat-filter:
        enabled: true
        url-pattern: /*
        #设置不统计哪些URL
        exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"
        session-stat-enable: true
        session-stat-max-count: 100
      stat-view-servlet:
        enabled: true
        url-pattern: /druid/*
        reset-enable: true
        #设置监控页面的登录名和密码
        login-username: admin
        login-password: admin
        allow: 127.0.0.1

#mybatis配置
mybatis:
  mapper-locations: classpath:/mapper/*/*.xml
  type-aliases-package: com.lee.mht.*.entity
  configuration:
    map-underscore-to-camel-case: true
#    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl   #用于控制台打印sql语句

#pagehelper配置

pagehelper:
#  helperDialect: mysql
  reasonable: true
  supportMethodsArguments: true
  params: count=countSql

然后就能用了

在这里插入图片描述

这里有个注意点,就是在你PageHelper.startPage后执行的第一条语句后才能分页

齐活

在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值