java list 分页

public static List<InvoiceProcessApplicationVo> getListPage(int page, int pageSize, List<InvoiceProcessApplicationVo> list) {
        if (list == null || list.size() == 0) {
            throw new RuntimeException("分页数据不能为空!");
        }
        
        int totalCount = list.size();
        page = page - 1;
        int fromIndex = page * pageSize;
        //分页不能大于总数
        if(fromIndex>=totalCount) {
            throw new RuntimeException("页数或分页大小不正确!");
        }
        int toIndex = ((page + 1) * pageSize);
        if (toIndex > totalCount) {
            toIndex = totalCount;
        }
        return list.subList(fromIndex, toIndex);
    }

猜你喜欢

转载自blog.csdn.net/weixin_40205234/article/details/85159729