Commit e0480f91 by WeiCong

优化分页查询响应返回页号逻辑

parent 3ca1d187
......@@ -173,11 +173,24 @@ public abstract class AbstractCache implements CacheController {
int total = moduleList.fullSize();
int index = paginationItem.get(Constants.PAGINATION_INDEX);
int pageSize=paginationItem.get(Constants.PAGINATION_PAGESIZE);
if (total < pageSize * index) {
index = (total % pageSize!=0) ? (total / pageSize + 1) : total / pageSize;
}
index=getPage(index,pageSize,total);
paginationInfo.put(Constants.PAGINATION_TOTAL, total);
paginationInfo.put(Constants.PAGINATION_INDEX, index);
return paginationInfo;
}
private static int getPage(int index,int pageSize,int total) {
if (pageSize <= 0) {
return 0;
}
index = index >= 1 ? (index <= getPages(pageSize,total) ? index : getPages(pageSize,total)) : 1;
return index;
}
private static int getPages(int pageSize,int total) {
if (pageSize <= 0) {
return 0;
}
return total % pageSize == 0 ? total / pageSize : total / pageSize + 1;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment