springboot PageHelper 分頁
阿新 • • 發佈:2021-11-09
PageHelper分頁是在開發專案的過程中使用過,故記錄下
新增依賴:
<dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.2.3</version> </dependency>
配置檔案:
public class ResponseWrapper<T> implementsSerializable { 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>