一个实现分页封装的类文件和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>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值