当前位置:   article > 正文

Spring Boot 配置PageHelper(Mybatis分页插件)_pagehelper application.properties

pagehelper application.properties

1 PageHelper

PageHelper是Github上开源的MyBatis分页插件,使用起来非常的简单,方便,并且支持任何复杂的单表、多表分页。

2 pom.xml(Maven依赖文件)

  1. <dependency>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-web</artifactId>
  4. </dependency>
  5. <!-- Mysql驱动包-->
  6. <dependency>
  7. <groupId>mysql</groupId>
  8. <artifactId>mysql-connector-java</artifactId>
  9. </dependency>
  10. <!-- Mybatis-->
  11. <dependency>
  12. <groupId>org.mybatis.spring.boot</groupId>
  13. <artifactId>mybatis-spring-boot-starter</artifactId>
  14. <version>2.1.4</version>
  15. </dependency>
  16. <!-- pagehelper 分页插件 -->
  17. <dependency>
  18. <groupId>com.github.pagehelper</groupId>
  19. <artifactId>pagehelper-spring-boot-starter</artifactId>
  20. <version>1.3.0</version>
  21. </dependency>

3 application.properties(配置文件)

  1. #数据库连接池设置
  2. spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
  3. spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8
  4. spring.datasource.username=root
  5. spring.datasource.password=root
  6. #mybatis的相关配置
  7. mybatis.mapper-locations=classpath:mapper/*.xml
  8. #pagehelper分页插件的数据库类型配置
  9. pagehelper.helper-dialect=mysql

4 UserController

  1. package com.controller;
  2. import com.entity.User;
  3. import com.github.pagehelper.PageHelper;
  4. import com.github.pagehelper.PageInfo;
  5. import com.service.UserService;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.web.bind.annotation.*;
  8. import java.util.List;
  9. @RestController
  10. @RequestMapping("/user")
  11. public class UserController {
  12. @Autowired
  13. private UserService userService;
  14. /**
  15. * 显示用户信息(分页)
  16. *
  17. * @param pageNum 页号
  18. * @param pageSize 每页显示记录数
  19. * @return
  20. */
  21. @GetMapping("/getUserList")
  22. public PageInfo<User> getUserList(@RequestParam int pageNum, @RequestParam int pageSize) {
  23. PageHelper.startPage(pageNum, pageSize);
  24. List<User> userList = userService.getUserList();
  25. PageInfo<User> pageInfo = new PageInfo<>(userList);
  26. return pageInfo;
  27. }
  28. }

 5 调试结果

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/87972
推荐阅读
相关标签
  

闽ICP备14008679号