标签:
package cn.wht.cookstore.model; import java.util.List; public class Page<T> { //页面传来的数据 private int pageNum; private int pageSize=1; //从数据库获取的数据 private int totalRecord; private List<T> recordList; //页面显示的数据 private int startPage; private int endPage; private int startIndex; private int pageCount; //上一页 下一页 private boolean hasPreviousPage; private boolean hasnextPage; private int previousPage; private int nextPage; //初始化数据 public Page(int totalRecord , int pageNum){ this.pageNum=pageNum; this.totalRecord=totalRecord; this.pageCount=(this.totalRecord+(this.pageSize-1))/pageSize; this.startIndex=(this.pageNum-1)*pageSize; if(this.pageCount<=10){ this.startPage=1; this.endPage=this.pageCount; }else{ this.startPage=this.pageNum-4; this.endPage=this.pageNum+5; if(this.startPage<1){ this.startPage=1; this.endPage=10; }else if(this.endPage>this.pageCount){ this.endPage=this.pageCount; this.startPage=this.pageCount-9; } } if(pageNum>1){ this.previousPage=this.pageNum-1; this.hasPreviousPage=true; } if(pageNum<this.pageCount){ this.nextPage=pageNum+1; this.hasnextPage=true; } } public int getPageNum() { return pageNum; } public void setPageNum(int pageNum) { this.pageNum = pageNum; } public int getPageSize() { return pageSize; } public void setPageSize(int pageSize) { this.pageSize = pageSize; } public int getTotalRecord() { return totalRecord; } public void setTotalRecord(int totalRecord) { this.totalRecord = totalRecord; } public List<T> getRecordList() { return recordList; } public void setRecordList(List<T> recordList) { this.recordList = recordList; } public int getStartPage() { return startPage; } public void setStartPage(int startPage) { this.startPage = startPage; } public int getEndPage() { return endPage; } public void setEndPage(int endPage) { this.endPage = endPage; } public int getStartIndex() { return startIndex; } public void setStartIndex(int startIndex) { this.startIndex = startIndex; } public int getPageCount() { return pageCount; } public void setPageCount(int pageCount) { this.pageCount = pageCount; } public boolean isHasPreviousPage() { return hasPreviousPage; } public void setHasPreviousPage(boolean hasPreviousPage) { this.hasPreviousPage = hasPreviousPage; } public boolean isHasnextPage() { return hasnextPage; } public void setHasnextPage(boolean hasnextPage) { this.hasnextPage = hasnextPage; } public int getPreviousPage() { return previousPage; } public void setPreviousPage(int previousPage) { this.previousPage = previousPage; } public int getNextPage() { return nextPage; } public void setNextPage(int nextPage) { this.nextPage = nextPage; } }
当前第[${page.pageNum }] <c:if test="${page.hasPreviousPage}"> <a href="${pageContext.request.contextPath }/manager/BookServlet?method=list&pageNum=${page.previousPage}">上一页</a> </c:if> <c:forEach var="pagenum" begin="${page.startPage }" end="${page.endPage }"> <a href="${pageContext.request.contextPath }/manager/BookServlet?method=list&pageNum=${pagenum}">[${pagenum }]</a> </c:forEach> <c:if test="${page.hasnextPage}"> <a href="${pageContext.request.contextPath }/manager/BookServlet?method=list&pageNum=${page.nextPage}">下一页</a> </c:if>
标签:
原文地址:http://blog.csdn.net/u012092620/article/details/44516875