Paging encapsulation utility and usage

Source: Internet
Author: User

Paging encapsulation utility and usage

Author: javaboy2012
Email: yanek@163.com
Qq: 1046011462

 

 

Package com. yanek. util; import java. util. list; public class PageBean {/*** @ param args */public static void main (String [] args) {} private int currentpage; // private int pagesize of the current page; // private int totalPagecount per page; // total number of pages private int totalRecordCount; // total number of records private List recordContents; // List of records on the current page public int getCurrentpage () {return currentpage;} public int getPagesize () {return pagesize;} public List buckets () {return recordContents;} public int getTotalPagecount () {return totalPagecount;} public int getTotalRecordCount () {return totalRecordCount;} public PageBean (int currentpage, int pagesize, int totalRecordCount, List recordContents) {super (); this. currentpage = currentpage; this. pagesize = pagesize; this. totalRecordCount = totalRecordCount; this. recordContents = recordContents; if (TotalRecordCount % pagesize = 0) {this. totalPagecount = totalRecordCount/pagesize;} else {this. totalPagecount = totalRecordCount/pagesize + 1 ;}} call method: action call: public ActionForward list (ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {TopicDAO tdao = new TopicDAOImpl (); String s_pagesize = (String) request. getParameter ("pagesize"); int pagesize = 20; If (s_pagesize! = Null) {pagesize = Integer. parseInt (s_pagesize);} int pagecount = 1; String s_pagecount = (String) request. getParameter ("pagecount"); if (s_pagecount! = Null) {pagecount = Integer. parseInt (s_pagecount);} // get the total number of records long totalcount = tdao. getTopicTotalCount (); System. out. println ("total:" + totalcount); List topics = tdao. getTopics (pagesize, pagecount); for (int I = 0; I <topics. size (); I ++) {TopicBean tb = (TopicBean) topics. get (I); System. out. println (tb. getTid () + "-" + tb. getTname ();} PageBean pb = new PageBean (pagecount, pagesize, (int) totalcount, topics); request. setAttribute ("t Opic_pagebean ", pb); return mapping. findForward ("topic_list");} jsp page call example: <% PageBean pb = (PageBean) request. getAttribute ("topic_pagebean"); List topics = pb. getRecordContents (); %> <div class = "cont"> <center> 

 

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.