SpringBoot

  1. 文章收集
  2. 集成PageHelper
  3. 自动装配原理

文章收集

集成PageHelper

  • 配置

    <!--基础框架包-->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-dependencies</artifactId>
      <version>2.3.4.RELEASE</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-dependencies</artifactId>
      <version>Hoxton.SR8</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
    <!--page helper依赖-->
    <!-- https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper-spring-boot-starter -->
    <dependency>
      <groupId>com.github.pagehelper</groupId>
      <artifactId>pagehelper-spring-boot-starter</artifactId>
      <version>1.3.0</version>
    </dependency>
    
  • 使用

    class XXService{
      public Result list(QueryParam param){
          PageMethod.startPage(param.getPageNumber(),param.getPageSize());
          List result = mapper.list(param);
          PageInfo pageInfo = new PageInfo(result);
          return PageDTO.result(pageInfo.getTotal(),result);
      }
    }
    
  • 注意事项

1.注意pom版本号
2.使用pagehelper-spring-boot-starter pom后,不需要在yml中配置pagehelper相关参数,否则分页会有问题(亲测)
  例如: 永远只在第一页

自动装配原理

@EnableAutoConfiguration
条件注解 @ConditionalOnBean等
@EnableAutoConfiguration注解(找META-INF/spring.factories配置文件中的所有自动配置类)

文章标题:SpringBoot

字数:307

本文作者:imfan

发布时间:2021-03-22, 09:44:01

最后更新:2021-10-25, 11:51:14

原始链接:https://wiki.aistart.cc/2021/03/22/backend/spring/spring-boot/

版权声明: "署名-非商用-相同方式共享 4.0" 转载请保留原文链接及作者。

×

喜欢就点赞,疼爱就打赏