您的位置:首页 > 编程语言 > Java开发

springboot实现分页插件

2020-08-15 14:32 423 查看

Spring Boot 集成 MyBatis, 分页插件 PageHelper, 通用 Mapper

1:添加pom文件依赖

<!--mybatis-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.1</version>
</dependency>
<!--mapper-->
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>1.2.4</version>
</dependency>
<!--pagehelper-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.3</version>
</dependency>

2.配置application.yml

分页配置

mybatis:
type-aliases-package: tk.mybatis.springboot.model
mapper-locations: classpath:mapper/*.xml

mapper:
mappers:
- tk.mybatis.springboot.util.MyMapper
not-empty: false
identity: MYSQL

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

3:代码使用

PageHelper.startPage(pageNum, pageSize);
List list= service.getList();
PageInfo pageInfo= new PageInfo<>(list);

SpringBoot实现PageHelper分页插件

项目依赖

<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>1.2.3</version>
</dependency>

配置核心类

@Configuration
@MapperScan("com.example.demo.mapper")
public class MyBatisConfig {

//配置PageHelper分页插件核心类
@Bean
public PaginationInterceptor paginationInterceptor(){
return new PaginationInterceptor();
}

}

yml配置

pagehelper:
helper-dialect: mysql
reasonable: true
support-methods-arguments: true
params: count=countSql
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: