网络编程 
首页 > 网络编程 > 浏览文章

简单实现jsp分页

(编辑:jimmy 日期: 2024/10/8 浏览:3 次 )

数据分页,在开发中必不可少,由于数据量太大,不得不进行处理。但是对于分页,又有很多种方式,比如使用sql语句的limit,或者使用jquery的插件。但是底层的逻辑,都是需要的。
在这里贴出bean对象的代码,以及一个辅助类。我做的这个项目是一个个人博客,算是个人网站吧。

(只贴部分底层逻辑代码)

Page.java

package cn.edu.ldu.util;

public class Page {

  private int everyPage;     //每页显示的数量
  private int totalPage;     //总页数
  private int totalCount;     //总数量
  private int currentPage;    //当前页
  private int beginIndex;     //起始页
  private boolean hasPrepage;   //是否有上一页
  private boolean hasNextPage;  //是否有下一页

  public Page() {
  }

  public Page(int everyPage, int totalPage, int totalCount, int currentPage,int beginIndex, boolean hasPrepage, boolean hasNextPage)
  {
    this.everyPage = everyPage;
    this.totalPage = totalPage;
    this.totalCount = totalCount;
    this.currentPage = currentPage;
    this.beginIndex = beginIndex;
    this.hasPrepage = hasPrepage;
    this.hasNextPage = hasNextPage;
  }

  public int getEveryPage() {
    return everyPage;
  }

  public void setEveryPage(int everyPage) {
    this.everyPage = everyPage;
  }

  public int getTotalPage() {
    return totalPage;
  }

  public void setTotalPage(int totalPage) {
    this.totalPage = totalPage;
  }

  public int getTotalCount() {
    return totalCount;
  }

  public void setTotalCount(int totalCount) {
    this.totalCount = totalCount;
  }

  public int getCurrentPage() {
    return currentPage;
  }

  public void setCurrentPage(int currentPage) {
    this.currentPage = currentPage;
  }

  public int getBeginIndex() {
    return beginIndex;
  }

  public void setBeginIndex(int beginIndex) {
    this.beginIndex = beginIndex;
  }

  public boolean isHasPrepage() {
    return hasPrepage;
  }

  public void setHasPrepage(boolean hasPrepage) {
    this.hasPrepage = hasPrepage;
  }

  public boolean isHasNextPage() {
    return hasNextPage;
  }

  public void setHasNextPage(boolean hasNextPage) {
    this.hasNextPage = hasNextPage;
  }

}

PageUtil.java

package cn.edu.ldu.util;

public class PageUtil {
  //创建分页信息对象
  public static Page createPage(int everyPage,int totalCount,int currentPage) {
    everyPage = getEveryPage(everyPage);
    currentPage = getCurrentPage(currentPage);
    int totalPage = getTotalPage(everyPage, totalCount);
    int beginIndex = getBeginIndex(everyPage, currentPage);
    boolean hasPrePage = getHasPrePage(currentPage);
    boolean hasNextPage = getHasNextPage(totalPage, currentPage);
    return new Page(everyPage, totalPage,totalCount, currentPage,
        beginIndex, hasPrePage, hasNextPage);
  }

  //获得每页显示记录数
  public static int getEveryPage(int everyPage) {
    return everyPage == 0 "htmlcode">
//传入每页显示的页数,总记录数,当前页
Page page=PageUtil.createPage(5, diaryDao.findAllCount(), currentPage);

简单实现jsp分页

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

上一篇:JSP中使用JDBC连接MySQL数据库的详细步骤
下一篇:JSP实现登录功能之添加验证码
一文看懂荣耀MagicBook Pro 16
荣耀猎人回归!七大亮点看懂不只是轻薄本,更是游戏本的MagicBook Pro 16.
人们对于笔记本电脑有一个固有印象:要么轻薄但性能一般,要么性能强劲但笨重臃肿。然而,今年荣耀新推出的MagicBook Pro 16刷新了人们的认知——发布会上,荣耀宣布猎人游戏本正式回归,称其继承了荣耀 HUNTER 基因,并自信地为其打出“轻薄本,更是游戏本”的口号。
众所周知,寻求轻薄本的用户普遍更看重便携性、外观造型、静谧性和打字办公等用机体验,而寻求游戏本的用户则普遍更看重硬件配置、性能释放等硬核指标。把两个看似难以相干的产品融合到一起,我们不禁对它产生了强烈的好奇:作为代表荣耀猎人游戏本的跨界新物种,它究竟做了哪些平衡以兼顾不同人群的各类需求呢?