Pagination
Introduction
Pagination is implemented based on PageHelper
, which is a pagination plugin for MyBatis
. It supports multiple databases, is easy to use, and does not depend on any third-party components.
Dependency
Add the dependency for pagehelper-spring-boot-starter
in the tang-commons/pom.xml
file. See pagehelper-spring-boot-starter for details.
xml
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
</dependency>
Usage
- The return type is
PageResult
, which represents the pagination result set that includes pagination information and data list. - Use
PageUtils.startPage()
to enable pagination.PageUtils.startPage()
automatically retrieves the pagination parameters (pageNum
andpageSize
). The default values for these parameters arepageNum = 1
andpageSize = 10
. - Use
PageUtils.getDataTable(list)
to get the pagination result set. Here,list
is the data list for pagination.
java
@GetMapping("/list")
public PageResult list(Custom custom){
PageUtils.startPage();
var list = customService.selectCustomList(custom);
return PageUtils.getDataTable(list);
}