ListUtil的page方法

调用PageUtil.setFirstPageNo(),如果firstPageNo不是从0开始计算会发生错误
This commit is contained in:
haochen.li 2020-10-21 22:42:43 +08:00
parent c4a91615b4
commit 5208e5b02d
2 changed files with 6 additions and 1 deletions

View File

@ -245,7 +245,7 @@ public class ListUtil {
int resultSize = list.size();
// 每页条目数大于总数直接返回所有
if (resultSize <= pageSize) {
if (pageNo < 1) {
if (pageNo < (PageUtil.getFirstPageNo()+1)) {
return Collections.unmodifiableList(list);
} else {
// 越界直接返回空

View File

@ -97,5 +97,10 @@ public class ListUtilTest {
Assert.assertArrayEquals(new int[]{3,4},c2);
Assert.assertArrayEquals(new int[]{5},c3);
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);
}
}