mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
ListUtil的page方法
调用PageUtil.setFirstPageNo(),如果firstPageNo不是从0开始计算会发生错误
This commit is contained in:
@@ -245,7 +245,7 @@ public class ListUtil {
|
|||||||
int resultSize = list.size();
|
int resultSize = list.size();
|
||||||
// 每页条目数大于总数直接返回所有
|
// 每页条目数大于总数直接返回所有
|
||||||
if (resultSize <= pageSize) {
|
if (resultSize <= pageSize) {
|
||||||
if (pageNo < 1) {
|
if (pageNo < (PageUtil.getFirstPageNo()+1)) {
|
||||||
return Collections.unmodifiableList(list);
|
return Collections.unmodifiableList(list);
|
||||||
} else {
|
} else {
|
||||||
// 越界直接返回空
|
// 越界直接返回空
|
||||||
|
@@ -97,5 +97,10 @@ public class ListUtilTest {
|
|||||||
Assert.assertArrayEquals(new int[]{3,4},c2);
|
Assert.assertArrayEquals(new int[]{3,4},c2);
|
||||||
Assert.assertArrayEquals(new int[]{5},c3);
|
Assert.assertArrayEquals(new int[]{5},c3);
|
||||||
Assert.assertArrayEquals(new int[]{},c4);
|
Assert.assertArrayEquals(new int[]{},c4);
|
||||||
|
|
||||||
|
|
||||||
|
PageUtil.setFirstPageNo(1);
|
||||||
|
int[] d1 = ListUtil.page(0,8,a).stream().mapToInt(Integer::valueOf).toArray();
|
||||||
|
Assert.assertArrayEquals(new int[]{1,2,3,4,5},d1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user