文章收集
集成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配置文件中的所有自动配置类)