/**
* 集合分页
*
* @param resourceList 要分页的集合
* @param pageIndex 页码
* @param pageSize 每页条数
* @return 分页后的集合
*/
public List<CommoditiesWithBLOBs> getPageByList(List<CommoditiesWithBLOBs> resourceList, int pageIndex, int pageSize) {
List<CommoditiesWithBLOBs> pageList = new ArrayList<>();
if (pageIndex < 1) {
pageIndex = 1;
}
int size = resourceList.size();
int pageCount = size / pageSize;
int fromIndex = (pageIndex - 1) * pageSize;
int toIndex = fromIndex + pageSize;
if (toIndex >= size) {
toIndex = size;
}
if (pageIndex > pageCount + 1) {
fromIndex = 0;
toIndex = 0;
}
pageList = resourceList.subList( fromIndex, toIndex );
return pageList;
}
转载,地址忘了。
此处仅做记录使用。