Simple jsp paging and jsp Paging

Source: Internet
Author: User

Simple jsp paging and jsp Paging

Data paging is essential during development. As the data volume is too large, it has to be processed. However, there are many paging methods, such as using SQL statement limit or jquery plug-in. However, the underlying logic is required.
Paste the bean object code and a helper class here. My personal blog Project is a personal website.

(Only part of the underlying logic code is pasted)

Page. java

Package cn.edu. ldu. util; public class Page {private int everyPage; // The number of private int totalPage displayed on each Page; // the total number of private int totalCount pages; // the total number of private int currentPage; // private int beginIndex on the current Page; // start Page private boolean hasPrepage; // whether the previous Page private boolean hasNextPage exists; // whether the next Page public Page exists () {} 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 {// create a Page information object 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 = getH AsNextPage (totalPage, currentPage); return new Page (everyPage, totalPage, totalCount, currentPage, beginIndex, hasPrePage, hasNextPage );} // obtain the number of records displayed on each page. public static int getEveryPage (int everyPage) {return everyPage = 0? 10: everyPage;} // get the current page public static int getCurrentPage (int currentPage) {return currentPage = 0? 10: currentPage;} // obtain the total number of pages. public static int getTotalPage (int everyPage, int totalCount) {int totalPage = 0; // determine whether each page is full, otherwise, the page number is + 1 if (totalCount! = 0 & totalCount % everyPage = 0) {totalPage = totalCount/everyPage;} else {totalPage = totalCount/everyPage + 1;} return totalPage ;} // get the starting position public static int getBeginIndex (int everyPage, int currentPage) {return everyPage * (currentPage-1);} // determine whether there is a previous page public static boolean getHasPrePage (int currentPage) {return currentPage = 1? False: true;} // determines whether the next page is public static boolean getHasNextPage (int totalPage, int currentPage) {return (currentPage = totalPage) | (totalPage = 0 )? False: true ;}}

You only need to call it each time.

// Input the number of pages per Page, total number of records. Current page Page = PageUtil. createPage (5, diaryDao. findAllCount (), currentPage );

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

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.