Skip to content

Commit dc407a8

Browse files
committed
fix(extension/crud): 修复 PageResp 手动分页计算错误
Closes #7
1 parent 99c9071 commit dc407a8

File tree

2 files changed

+4
-8
lines changed
  • continew-starter-extension/continew-starter-extension-crud
    • continew-starter-extension-crud-mf/src/main/java/top/continew/starter/extension/crud/model/resp
    • continew-starter-extension-crud-mp/src/main/java/top/continew/starter/extension/crud/model/resp

2 files changed

+4
-8
lines changed

continew-starter-extension/continew-starter-extension-crud/continew-starter-extension-crud-mf/src/main/java/top/continew/starter/extension/crud/model/resp/PageResp.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,10 @@ public static <L> PageResp<L> build(int page, int size, List<L> list) {
9393
pageResp.setTotal(list.size());
9494
// 对列表数据进行分页
9595
int fromIndex = (page - 1) * size;
96-
int toIndex = page * size + fromIndex;
97-
if (fromIndex > list.size()) {
96+
if (fromIndex >= list.size()) {
9897
pageResp.setList(new ArrayList<>(0));
99-
} else if (toIndex >= list.size()) {
100-
pageResp.setList(list.subList(fromIndex, list.size()));
10198
} else {
99+
int toIndex = Math.min(fromIndex + size, list.size());
102100
pageResp.setList(list.subList(fromIndex, toIndex));
103101
}
104102
return pageResp;

continew-starter-extension/continew-starter-extension-crud/continew-starter-extension-crud-mp/src/main/java/top/continew/starter/extension/crud/model/resp/PageResp.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,10 @@ public static <L> PageResp<L> build(int page, int size, List<L> list) {
9393
pageResp.setTotal(list.size());
9494
// 对列表数据进行分页
9595
int fromIndex = (page - 1) * size;
96-
int toIndex = page * size + fromIndex;
97-
if (fromIndex > list.size()) {
96+
if (fromIndex >= list.size()) {
9897
pageResp.setList(new ArrayList<>(0));
99-
} else if (toIndex >= list.size()) {
100-
pageResp.setList(list.subList(fromIndex, list.size()));
10198
} else {
99+
int toIndex = Math.min(fromIndex + size, list.size());
102100
pageResp.setList(list.subList(fromIndex, toIndex));
103101
}
104102
return pageResp;

0 commit comments

Comments
 (0)