java 8 分页处理

//封装count 和 list
public class PageResult implements Serializable {
    private int count;
    private List item;

    public PageResult(int count, List item) {
        this.count = count;
        this.item = item;
    }

    public int getCount() {
        return this.count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public List getItem() {
        return this.item;
    }

    public void setItem(List item) {
        this.item = item;
    }
}
 /**   pageNo 从1开始
     * 分页处理
     */
    private PageResult getFilterList(List list, int pageNo, int pageSize) {
        if ((pageNo-1) * pageSize > list.size()) {
            return new PageResult(list.size(), Collections.EMPTY_LIST);
        }
        list = list.stream().skip((pageNo-1) * pageSize).limit(pageSize).collect(Collectors.toList());
        return new PageResult(list.size(),list );
    }

你可能感兴趣的:(java 8 分页处理)