springboot分页查询mysql
时间: 2023-10-12 13:56:22 浏览: 96
在Spring Boot中进行MySQL的分页查询,可以使用PageHelper插件来实现。首先,需要在pom.xml文件中引入PageHelper插件的依赖。这里引入的是整合到Spring Boot后的PageHelper插件,不需要剔除mybatis-spring-boot-starter的依赖。以下是引入PageHelper插件的依赖的示例代码:
```xml
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.3</version>
<exclusions>
<exclusion>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
</exclusion>
</exclusions>
</dependency>
```
接下来,在application.yml配置文件中添加PageHelper的配置。以下是配置示例代码:
```yaml
pagehelper:
helperDialect: mysql
reasonable: true
support-methods-arguments: true
params: count=countSql
```
最后,在启动类Application.java中初始化PageHelper插件。以下是初始化PageHelper插件的示例代码:
```java
@Bean
public PageHelper pageHelper(){
PageHelper pageHelper = new PageHelper();
Properties properties = new Properties();
properties.setProperty("offsetAsPageNum","true");
properties.setProperty("rowBoundsWithCount","true");
properties.setProperty("reasonable","true");
properties.setProperty("dialect","mysql");
pageHelper.setProperties(properties);
return pageHelper;
}
```
通过以上配置,就可以在Spring Boot中进行MySQL的分页查询了。
#### 引用[.reference_title]
- *1* *2* *3* [springboot的分页实现:使用gitHub插件PageHelper实现mysql数据库查询分页功能](https://blog.csdn.net/zhanglf02/article/details/89916420)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文