Pageutil Sub-page

Source: Internet
Author: User

Idea: First with MySQL, the main paging is the limit function, limit the first parameter is from the beginning (mysql default is 0), the second is fixed, each page shows the number of bars.


Properties: PageCount The number of bars displayed per page, how many resultcount there are, currentpage the current page, and how many pages totalpage altogether

Method: GetCurrent (int currentpage,int pagecount) is used to calculate the first parameter of limit, with (the current page-1) * The number of bars displayed per page

Getfooter (int resultcount,int pagecount,int currentpage) is used to display the page footer, which controls the display of the next page of the previous page

package com.liyi.test.util;public class pageutil {    /** number of bars displayed per page **/     private int pagecount;    /** total number of bars **/     private int resultcount;    /** Current Page **/    private  int currentpage;    /** altogether how many pages **/    private int  Totalpage;    public int getresultcount ()  {         return resultcount;    }    public void  setresultcount (Int resultcount)  {         This.resultcount = resultcount;    }    public int  getcurrentpage ()  {        return currentPage;     }    publIc void setcurrentpage (int currentpage)  {         this.currentpage = currentpage;    }             public int gettotalpage ()  {         return totalPage;    }    public void  Settotalpage (int totalpage)  {        this.totalpage =  totalPage;    }        public int  Getpagecount ()  {        return pageCount;     }    public void setpagecount (Int pagecount)  {         this.pageCount = pageCount;    }          public pageutil ()  {        // TODO  auto-generated constructor stub    }    /**      *  calculation starting from the first      *  @param  currentPage      *  @param  pageCount     *  @return       */    public int getcurrent (Int currentpage,int pagecount) {        return  (currentPage-1) *pagecount;     }        public string getfooter (Int resultCount, Int pagecount,int currentpage) {&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;STRINGBUFFER&NBSP;SB  = new stringbuffer ();         if (resultCount>0& &pagecount>resultcount) {            totalPage = 1;         }else if (Resultcount>0&&pagecount<resultcount) {             totalpage = resultcount%pagecount==0? Resultcount/pagecount:resultcount/pagecount+1;        }else if ( resultcount==0) {            totalpage =  0;        }        sb.append (" Total "+totalpage+"). Append ("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");         if (currentpage<=totalpage&&currentpage!=1) {             sb.append ("<a href= ' javascript:void ( 0); '  id= ' pre ' >Prev </a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ");         }else{             sb.append ("previous page &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp; ");         }        sb.append (" Currently <b id= ' current ' > ' +currentpage+ ' </b> page &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ");         if (currentpage<totalpage) {             sb.append ("<a href= ' javascript:void (0); '  id= ' Next ' > Next </a> '). Append ("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp; ");         }else{         & nbSp;  sb.append ("next Page"). Append ("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; ");         }        sb.append ("Total" +resultcount+ "Bar");         return sb.tostring ();             }}
@RequestMapping ("/selectuserlist")     public modelandview selectuserlist ( Httpservletrequest request, @RequestParam                                            Map<String,Object>  Conds) {        map<string,object> map = new  Hashmap<string, object> ();         int currentpage  =1;        //used to determine whether it is the previous page or the next page          String type =  (String)  conds.get ("type");         //is used to accept the page's current number of pages, if initialization is 1        string current=  ( String)  conds.get ("CurrentPage");         if (Null!=type) {             if ("1". Equals (type)) {                 if (null!=current) {                     currentpage =integer.valueof ( Current) +1;                }             }else if ("2". Equals (type)) {                 if (null!=current) {                      currentpage =integer.valueof (current) -1;                 }            }                     }         //set number of bars per page         int  Pagecount =3;        map.put ("PageCount", PageCount);         //query out the total number of records for paging calculation         int  Count = userservice.gettotalpage ();        pageutil  Page = new pageutil ();         //used to calculate the first parameter of limit    Based on the current page         map.put ("CurrentPage", Page.getcurrent (CurrentPage, PageCount))         //the following footer          string footer&nbSp;= page.getfooter (count, pagecount, currentpage);         list<userpo> list = userservice.findall (map);         modelmap modelmap = new modelmap ();         modelmap.addattribute ("list", list);         modelmap.addattribute ("Footer", footer);        modelandview modelandview =  New modelandview ("User/user_list", Modelmap);        return  modelandview;    }
            $ ("#next"). Click (function () {                 var current=$ (" #current "). HTML ();                 window.location.href= "${app}/usercontroller/" +current+ ' &type=1 ';             })                          $ ("#pre" ). Click (function () {                 var current=$ ("#current"). HTML ();                 window.location.href= "${app}/usercontroller/" + current+ ' &type=2 ';             }) 

Pageutil Sub-page

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: 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.