自定义分页

需求背景:两个接口获取列表数据,(实时流水与历史流水)。实时流水接口返回数据条数不定,不能分页返回。历史流水可分页返回。这两个接口揉成一个列表,要求能正常返回分页数据。

算法说明:
1.获取全部实时流水(currentList)
2. 计算实时流水能填充的页码(cPage=currentList/pageSize)与余数(cRemainder = currentList%pageSize)
3. 判断当前所需页码。
a. pageNo < cPage : 直接截取currentList返回
b. pageNo > cPage则:
调用两页历史流水,前一页(prePage = pageNo - cPage - 1)与当前页(curPage = pageNo - cPage)
如果prePage == 0, 则截取实时流水最后cRemainder条
如果prePage > 0,则获取历史流水,并截取最后cRemainder条

当前页流水截取前(pageSize - cRemainder) 条。

记得做数据判断避免IndexOutOfBoundsException与NullPointerException

第一页第二页第三页
currentDatacurrentData (余数)historyData
currentDatacurrentData (余数)historyData
currentDatahistoryDatahistoryData
currentDatahistoryDatahistoryData
currentDatahistoryDatahistoryData
currentDatahistoryDatahistoryData
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值