MyBatisPlus IPage pagination plug-in I specially compiled an article as follows
Mybatis plus paging plug-in: PageHelper+BootStrap+Vue+axios realizes paging function
Next, introduce GitHub's PageHelper
First import dependencies
<!--springboot整合pagehelper-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.3.1</version>
</dependency>
RequestParam.java
@Data//Lombok插件
public class RequestParam<T> {
private Integer pageNum;
private Integer pageSize;
private T data;
}
service layer (the following Goods are my entity classes and can be changed according to your own needs)
HttpResult<?> queryGoodByNameAndStatus(RequestParam<Goods> param);
Service layer implementation class
@Override
public HttpResult<?> queryGoodByNameAndStatus(RequestParam<Goods> param) {
//分页开始
PageHelper.startPage(param.getPageNum(),param.getPageSize());
//调用mapper层接口
List<Goods> goods = goodMapper.queryGoodByNameAndStatus(param.getData().getName(), 0);
//把mapper接口返回参数放入pageInfo
PageInfo pageInfo=new PageInfo(goods);
return new HttpResult<>().ok(pageInfo);
}
Controller layer
@PostMapping("queryGood")
public HttpResult<?> queryGood(@RequestBody RequestParam<Goods> requestParam) {
log.info(JSON.toJSONString(requestParam));
return userService.queryGoodByNameAndStatus(requestParam);
}
Summarize:
IPage is a plug-in that comes with MybatisPlus and does not need to introduce additional dependencies, but query paging needs to define a special interface that contains parameters of the IPage type.
PageHelper needs to introduce additional dependencies, but it is not mandatory to use a special interface containing paging parameters, and you can directly use the existing List query interface.