简单的对list进行分页

来源:互联网 发布:瑞典帅哥成灾 知乎 编辑:程序博客网 时间:2024/06/07 18:13
  /**
     * 将List分页显示
     * 
     * @param list        分页的List
     * @param currentPage 显示那一页
     * @param pageSize 每页显示数量     
     * @return List<Object>
     */
    public static List showResulWithPage(List list, Integer currentPage, Integer pageSize) {


        if (currentPage == null) {
            throw new IllegalArgumentException("currentPage is null.");
        }
        if (pageSize == null) {
            throw new IllegalArgumentException("pageSize is null.");
        }
        if (list.size() == 0 || list == null) {
            return null;
        }


        List listNew = new ArrayList();
        for (int i = (currentPage - 1) * pageSize; i < currentPage * pageSize && i < list.size(); i++) {
            listNew.add(list.get(i));
        }


        return listNew;


    }
0 0