后台集合分页

本文介绍了一个基于条件的设备状态分页查询API实现,通过解析设备类型、区域ID、设备名称等参数,从数据库中获取设备状态信息,并利用PageUtil进行分页处理,返回特定页数和页面大小的数据集合。
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); }

 

转载于:https://www.cnblogs.com/maocai2018/p/10117148.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值