fix(extension/crud): 修复 PageResp 手动分页计算错误

Closes #7
This commit is contained in:
2024-12-06 21:53:10 +08:00
parent 99c9071eae
commit dc407a82cc
2 changed files with 4 additions and 8 deletions

View File

@@ -93,12 +93,10 @@ public class PageResp<L> extends BasePageResp<L> {
pageResp.setTotal(list.size());
// 对列表数据进行分页
int fromIndex = (page - 1) * size;
int toIndex = page * size + fromIndex;
if (fromIndex > list.size()) {
if (fromIndex >= list.size()) {
pageResp.setList(new ArrayList<>(0));
} else if (toIndex >= list.size()) {
pageResp.setList(list.subList(fromIndex, list.size()));
} else {
int toIndex = Math.min(fromIndex + size, list.size());
pageResp.setList(list.subList(fromIndex, toIndex));
}
return pageResp;

View File

@@ -93,12 +93,10 @@ public class PageResp<L> extends BasePageResp<L> {
pageResp.setTotal(list.size());
// 对列表数据进行分页
int fromIndex = (page - 1) * size;
int toIndex = page * size + fromIndex;
if (fromIndex > list.size()) {
if (fromIndex >= list.size()) {
pageResp.setList(new ArrayList<>(0));
} else if (toIndex >= list.size()) {
pageResp.setList(list.subList(fromIndex, list.size()));
} else {
int toIndex = Math.min(fromIndex + size, list.size());
pageResp.setList(list.subList(fromIndex, toIndex));
}
return pageResp;