Simple implementation of JSP paging _jsp programming

Source: Internet
Author: User

Data paging, in the development of essential, because the amount of data is too large, have to deal with. But for pagination, there are a number of ways, such as using the limit of SQL statements, or using jquery plug-ins. But the underlying logic is all that is needed.
The code for the Bean object is posted here, along with a helper class. I do this project is a personal blog, is a personal site it.

(only some of the underlying logic code is attached)

Page.java

Package cn.edu.ldu.util;     public class Page {private int everypage;     Number of display per page private int totalpage;     Total pages private int totalcount;    Total quantity private int currentpage;     Current page private int beginindex;   Start Page Private Boolean hasprepage;  Whether there is a previous page private Boolean hasnextpage; Whether there is a next page public page () {} public page (int everypage, int totalpage, int totalcount, int currentpage,int Begininde
    X, 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;
  The public void seteverypage (int everypage) {this.everypage = Everypage;
  public int gettotalpage () {return totalpage;
  The public void settotalpage (int totalpage) {this.totalpage = Totalpage; } public int Gettotalcount () {return totalcount;
  The public void Settotalcount (int totalcount) {this.totalcount = TotalCount;
  public int getcurrentpage () {return currentpage;
  The public void setcurrentpage (int currentpage) {this.currentpage = CurrentPage;
  public int Getbeginindex () {return beginindex;
  The 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 {//Create paging Information object public static Page createpage (int everypage,int totalcount,int currentpage) {E
    Verypage = 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);
  //Get the number of display records per page public static int geteverypage (int everypage) {return everypage = 0? 10:everypage;
  //Get current page public static int getcurrentpage (int currentpage) {return currentpage = 0? 10:currentpage;
    //Get total number of pages public static int gettotalpage (int everypage,int totalcount) {int totalpage=0; To determine if each page is full, page +1 if (totalcount!=0 && totalcount%everypage==0) {TOtalpage=totalcount/everypage;
    else {totalpage=totalcount/everypage+1;
  return totalpage;
  ///Get start position public static int Getbeginindex (int everypage,int currentpage) {return everypage* (currentPage-1);

  //Determine if there is a previous page public static Boolean gethasprepage (int currentpage) {return currentpage== 1? false:true; //Determine if there is a next page public static Boolean gethasnextpage (int totalpage, int currentpage) {return (currentpage = = Totalp Age) | | (totalpage = 0)?
  False:true;


 }

}

Every time I just need to call it.

The number of pages to be displayed per page, total records, current page
page=pageutil.createpage (5, Diarydao.findallcount (), currentpage);

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.