PageHelper分页是在开发项目的过程中使用过,故记录下
添加依赖:
<dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.2.3</version> </dependency>
配置文件:
public class ResponseWrapper<T> implements Serializable { private String code = "200"; private String msg; private T data; public ResponseWrapper(String code, String msg) { this.code = code; this.msg = msg; } public ResponseWrapper() { } public String getCode() { return code; } public void setCode(String code) { this.code = code; } public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } public T getData() { return data; } public ResponseWrapper setData(T data) { this.data = data; return this; } public ResponseWrapper error(String code, String msg) { this.code = code; this.msg = msg; return this; } }
实体类FetchManagerVo
import lombok.Data; @Data public class FetchManagerVo { private String id;private int pageNum; private int pageSize; }
controller层
/**
* 取数需求列表(分页)
*/
@PostMapping(value = "/fetchManageList")
public Object getFetchManageList(@RequestBody FetchManagerVo fetchManagerVo){
return fetchManagerService.getFetchManageList(fetchManagerVo);
}
service层
public ResponseWrapper getFetchManageList(FetchManagerVo fetchManagerVo) { PageHelper.startPage(fetchManagerVo.getPageNum(),fetchManagerVo.getPageSize()); List<FetchManager> listData = fetchManageMapper.getFetchManageList(fetchManagerVo); return new ResponseWrapper<PageInfo>().setData(new PageInfo(listData)); }
mapper层
List<FetchManager> getFetchManageList(FetchManagerVo fetchManagerVo);
xml层
<select id="getFetchManageList" resultType="com.bonc.netax.bean.FetchManager"> select * from test order by input_time desc </select>