PageView.java:
package com.itcast.util;
import java.util.List;
public class PageView<T> {
private List<T> contents;
private long start;
private long end;
private long totalPage;
/**
* 记录总数
*/
private long totalRec;
private int currentPage;
/**
* 每页显示的数量
*/
private int number = 8;
public PageView(int currentPage){
this.currentPage = currentPage;
}
public void initPage(QueryResult qr){
this.totalRec = qr.getTotalrecord();
this.totalPage = this.totalRec % this.number ==0?this.totalRec / this.number :this.totalRec / this.number + 1;
this.start = 1;
this.end = this.totalPage == 0?1:this.totalPage;
this.contents = qr.getResultList();
}
public int getNumber() {
return number;
}
public int getCurrentPage() {
return currentPage;
}
public List<T> getContents() {
return contents;
}
public void setContents(List<T> contents) {
this.contents = contents;
}
public long getStart() {
return start;
}
public void setStart(long start) {
this.start = start;
}
public long getEnd() {
return end;
}
public void setEnd(long end) {
this.end = end;
}
public long getTotalPage() {
return totalPage;
}
public void setTotalPage(long totalPage) {
this.totalPage = totalPage;
}
public long getTotalRec() {
return totalRec;
}
public void setTotalRec(long totalRec) {
this.totalRec = totalRec;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public void setNumber(int number) {
this.number = number;
}
}
fenye.jsp:
<%@ page language="java" pageEncoding="UTF-8"%>
<font color="#FFFFFF">
当前页:第${pageView.currentPage}页 | 总记录数:${pageView.totalRec}条 | 每页显示:${pageView.number}条 | 总页数:${pageView.totalPage}页</font>
<c:forEach begin="${pageView.start}" end="${pageView.end}" var="wp">
<c:if test="${pageView.currentPage==wp}"><b><font color="#FFFFFF">第${wp}页</font></b></c:if>
<c:if test="${pageView.currentPage!=wp}"><a href="javascript:topage('${wp}')" class="a03">第${wp}页</a></c:if>
</c:forEach>