赞
踩
PageHelper是Github上开源的MyBatis分页插件,使用起来非常的简单,方便,并且支持任何复杂的单表、多表分页。
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- </dependency>
- <!-- Mysql驱动包-->
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- </dependency>
-
- <!-- Mybatis-->
- <dependency>
- <groupId>org.mybatis.spring.boot</groupId>
- <artifactId>mybatis-spring-boot-starter</artifactId>
- <version>2.1.4</version>
- </dependency>
- <!-- pagehelper 分页插件 -->
- <dependency>
- <groupId>com.github.pagehelper</groupId>
- <artifactId>pagehelper-spring-boot-starter</artifactId>
- <version>1.3.0</version>
- </dependency>
- #数据库连接池设置
- spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
- spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8
- spring.datasource.username=root
- spring.datasource.password=root
-
- #mybatis的相关配置
- mybatis.mapper-locations=classpath:mapper/*.xml
- #pagehelper分页插件的数据库类型配置
- pagehelper.helper-dialect=mysql
- package com.controller;
-
- import com.entity.User;
- import com.github.pagehelper.PageHelper;
- import com.github.pagehelper.PageInfo;
- import com.service.UserService;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
-
- import java.util.List;
-
- @RestController
- @RequestMapping("/user")
- public class UserController {
- @Autowired
- private UserService userService;
-
- /**
- * 显示用户信息(分页)
- *
- * @param pageNum 页号
- * @param pageSize 每页显示记录数
- * @return
- */
- @GetMapping("/getUserList")
- public PageInfo<User> getUserList(@RequestParam int pageNum, @RequestParam int pageSize) {
- PageHelper.startPage(pageNum, pageSize);
- List<User> userList = userService.getUserList();
- PageInfo<User> pageInfo = new PageInfo<>(userList);
- return pageInfo;
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。