代码语言:javascript复制
public List pageList(List resList, int page, int limit) {
List resultList = null;
if (resList != null && resList.size() != 0) {
if (page != 0 && limit != 0) {
Integer count = resList.size(); // 记录总数
Integer pageCount = 0; // 页数
if (count % limit == 0) {
pageCount = count / limit;
} else {
pageCount = count / limit 1;
}
int fromIndex = 0; // 开始索引
int toIndex = 0; // 结束索引
if (page != pageCount) {
fromIndex = (page - 1) * limit;
toIndex = fromIndex limit;
} else {
fromIndex = (page - 1) * limit;
toIndex = count;
}
resultList = resList.subList(fromIndex, toIndex);
} else {
resultList = resList;
}
}
return resultList;
}