java自定义分页对象

public class<T> PageBean {undefined
    private int currPage; // 当前页数.
    private int totalCount; // 总记录数.
    private int totalPage; // 总页数.
    private int pageSize;// 每页记录数.
    private List<T> list; // 每页的数据的集合
    public int getCurrPage() {undefined
        return currPage;
    }
    public void setCurrPage(int currPage) {undefined
        this.currPage = currPage;
    }
    public int getTotalCount() {undefined
        return totalCount;
    }
    public void setTotalCount(int totalCount) {undefined
        this.totalCount = totalCount;
    }
    public int getTotalPage() {undefined
        return totalPage;
    }
    public void setTotalPage(int totalPage) {undefined
        this.totalPage = totalPage;
    }
    public int getPageSize() {undefined
        return pageSize;
    }
    public void setPageSize(int pageSize) {undefined
        this.pageSize = pageSize;
    }
    public List<T> getList() {undefined
        return list;
    }
    public void setList(List<T> list) {undefined
        this.list = list;
    }
}
 

//业务层方法封装;

public PageBean findByPage(int currPage) throws SQLException {undefined
        PageBean pageBean = new PageBean();
        // 设置pageBean的参数:
        // 设置当前页数:
        pageBean.setCurrPage(currPage);
        // 设置每页显示记录数:
        int pageSize = 10;
        pageBean.setPageSize(pageSize);
        // 设置总记录数:
        ProductDao productDao = new ProductDao();
        int totalCount = productDao.findCount();
        pageBean.setTotalCount(totalCount);
        // 设置总页数:
        /*int totalPage = 0;
        if(totalCount % pageSize == 0){undefined
            totalPage = totalCount / pageSize;
        }else{undefined
            totalPage = totalCount / pageSize + 1;
        }*/
        double tc = totalCount;
        Double num = Math.ceil(tc/pageSize);
        pageBean.setTotalPage(num.intValue());
        // 设置每页显示的数据的集合:
        int begin = (currPage - 1)* pageSize;
        List<Product> list = productDao.findByPage(begin,pageSize);
        pageBean.setList(list);
        return pageBean;
    }
上一篇:less命令自动解压gz压缩文件


下一篇:PyTorch 介绍 | TRANSFORMS