当前位置:   article > 正文

springBoot的分页插件_springboot分页插件

springboot分页插件

目录

1、加入依赖

2、配置分页插件

3、使用分页插件


1、加入依赖

  1. <!-- 分页插件-->
  2. <dependency>
  3. <groupId>com.github.pagehelper</groupId>
  4. <artifactId>pagehelper-spring-boot-starter</artifactId>
  5. <version>1.3.0</version>
  6. </dependency>

2、配置分页插件

  1. #指定数据库
  2. pagehelper.helper-dialect=mysql
  3. #是否启用分页合理化,当pagenum<1时,自动查寻第一页数据,当pegenum>pages时,最后查询最后一页数据
  4. pagehelper.reasonable=true
  5. #支持分页参数写在mapper接口的方法里(方法中传参)
  6. pagehelper.support-methods-arguments=true
  7. pagehelper.params=count=countSql

         注:如果报循环依赖的错误:

┌──->──┐
|  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.

在配置文件中加入解决循环依赖的配置

  1. #解决循环依赖
  2. spring.main.allow-circular-references=true

3、使用分页插件

  1. //方法中的pageNum和pageSize两个参数,在dao和service层的方法中无需传参
  2. @GetMapping("/user")
  3. public String queryPageUser(@RequestParam(value = "pageNum",defaultValue = "1",required = false) Integer pageNum,
  4. @RequestParam(value = "pageSize",defaultValue = "2",required = false) Integer pageSize) throws JsonProcessingException {
  5. PageHelper.startPage(pageNum,pageSize);
  6. List<User> list = userService.queryPageUser();
  7. PageInfo<User> userPageInfo = new PageInfo<>(list);
  8. String s = objectMapper.writeValueAsString(userPageInfo);
  9. return s;
  10. }
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/88133
推荐阅读
相关标签
  

闽ICP备14008679号