PageBean.java代码
public class PageBean { private int total; private int totalPage; private int pageNum; private int start; private int offset = 4; private List<Integer> pages = new ArrayList<Integer>(); private int pre; private int next; public static final int SIZE = 5; public PageBean(int pageNum,int total) { this.pageNum = pageNum; this.total = total; getTotalPage(); getStart(); getPages(); getPre(); getNext(); } public int getTotal() { return total; } public void setTotal(int total) { this.total = total; } public int getTotalPage() { if(total%sIZE==0) { totalPage = total/SIZE; } else { totalPage = total/SIZE + 1; } return totalPage; } public static int getTotalPage(int total,int size) { int totalPage = 0; if(total%size==0) { totalPage = total/size; } else { totalPage = total/size + 1; } return totalPage; } public int getPageNum() { return pageNum; } public void setPageNum(int pageNum) { this.pageNum = pageNum; } public int getStart() { start = (pageNum-1) * SIZE; return start; } public int getoffset() { return offset; } public void setoffset(int offset) { this.offset = offset; } public List<Integer> getPages() { pages.clear(); int s = (pageNum - offset)>0?(pageNum - offset):1; int e = (pageNum + offset)>totalPage?totalPage:(pageNum + offset); for(int i=s; i<=e; i++) { pages.add(i); } return pages; } public void setPages(List<Integer> pages) { this.pages = pages; } public int getPre() { pre = pageNum - 1; return pre; } public void setPre(int pre) { this.pre = pre; } public int getNext() { next = pageNum +1; return next; } public void setNext(int next) { this.next = next; } }
前台veLocity代码
<div class="pagination pagination-centered"> <ul> #if($pageBean.pageNum==1) <li class="disabled"><a>首页</a></li> #else <li><a href="/app/page.do?pageNum=1">首页</a></li> #end #if($pageBean.pageNum==1) <li class="disabled"><a>«</a></li> #else <li><a href="/app/page.do?pageNum=$pageBean.pre" class="active">«</a></li> #end #foreach($p in $pageBean.pages) #if($p==$pageBean.pageNum) <li class="disabled"><a>$p</a></li> #else <li><a href="/app/page.do?pageNum=$p">$p</a></li> #end #end #if($pageBean.pageNum==$pageBean.totalPage) <li class="disabled"><a>»</a></li> #else <li><a href="/app/page.do?pageNum=$pageBean.next">»</a></li> #end #if($pageBean.pageNum==$pageBean.totalPage) <li class="disabled"><a>末页</a></li> #else <li><a href="/app/page.do?pageNum=$pageBean.totalPage">末页</a></li> #end </ul> </div>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。