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>