后台集合分页

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); }

猜你喜欢

转载自www.cnblogs.com/maocai2018/p/10117148.html