基于bootstrap + velocity的分页实现

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>

相关文章

Bootstrip HTML 查询搜索常用格式模版 &lt;form class=&...
如何在按钮上加红色数字 您可以使用Bootstrap的badge组件来在...
要让两个按钮左右排列,你可以使用 Bootstrap 的网格系统将它...
是的,可以将status设置为布尔类型,这样可以在前端使用复选...
前端工程师一般用的是Bootstrap的框架而不是样式,样式一般自...
起步导入:<linkrel="stylesheet"href="b...