一个实现分页封装的类文件和jsp文件

本文介绍了一个自定义的分页工具类PageView及其在JSP页面上的应用实例。PageView类通过传入当前页码和查询结果来初始化分页信息,如记录总数、总页数等,并将这些数据显示在fenye.jsp页面上。

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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值