分页



public class PageBean {


private int pageNum; // 页码
private int currentPage; // 每页条数
private int totalPage; // 总页数
private int totalCount; // 总条数
private List cs; // 每页数据


public int getPageNum() {
return pageNum;
}


public void setPageNum(int pageNum) {
this.pageNum = pageNum;
}


public int getCurrentPage() {
return currentPage;
}


public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}


public int getTotalPage() {
return totalPage;
}


public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}


public int getTotalCount() {
return totalCount;
}


public void setTotalCount(int totalCount) {
this.totalCount = totalCount;
}


public List getCs() {
return cs;
}


public void setCs(List cs) {
this.cs = cs;
}


}


       // 分页操作
// pageNum 页码
// currentPage 每页条数
public PageBean findByPage(int pageNum, int currentPage)
throws SQLException {


PageBean pb = new PageBean();


List cs = dao.findByPage(pageNum, currentPage);


// 查询总条数:
int totalCount = dao.findAllCount();


// 得到总页数
int totalPage = (int) Math.ceil(totalCount * 1.0 / currentPage);


pb.setTotalCount(totalCount); // 封装总条数
pb.setTotalPage(totalPage);// 封装总页数
pb.setCs(cs);// 封装当前页数据.
pb.setCurrentPage(currentPage); // 封装每页条数
pb.setPageNum(pageNum);// 封装当前页码


return pb;
}

你可能感兴趣的:(分页)