后台集合分页
Posted maocai2018
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了后台集合分页相关的知识,希望对你有一定的参考价值。
public ApiResult getState(@FormParam("deviceType") int deviceType, @FormParam("precinctId") String precinctId, @FormParam("deviceName") String deviceName, @FormParam("onLine") String onLine, @FormParam("pageNo") int pageNo, @FormParam("pageSize") int pageSize) {
//根据条件获取到的集合 List<DeviceStatePojoVo> state = deviceMonitorService.getState(deviceType, precinctId, deviceName, onLine); List<DeviceStatePojoVo> stateList = null; int length = state.size(); if (length > 0) { //默认 int startIndex = 0; int endIndex = 10; int no = 1; int size = 10; if (pageSize > 0 && pageSize <= length) { size = pageSize; } int pages = length / size; if (length > pages * size) { pages += 1; //页数 } if (pageNo > 0 && pageNo <= pages) { no = pageNo; } else { no = 1; } startIndex = (no - 1) * size; endIndex = no * size; if (endIndex > length) {//防止下标越界 endIndex = length; } stateList = state.subList(startIndex, endIndex); //两个值都是下标 } PageUtil pageUtil = new PageUtil(state.size(), stateList); return new ApiResult(ApiCode.SUCCESS, pageUtil); }
以上是关于后台集合分页的主要内容,如果未能解决你的问题,请参考以下文章
modx - 当我在同上片段中使用“&documents =”参数时,分页不起作用