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.
Pageutil
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 (" "); if (currentpage<=totalpage&¤tpage!=1) { sb.append ("<a href= ' javascript:void ( 0); ' id= ' pre ' >Prev </a> "); }else{ sb.append ("previous page & nbsp; "); } sb.append (" Currently <b id= ' current ' > ' +currentpage+ ' </b> page "); if (currentpage<totalpage) { sb.append ("<a href= ' javascript:void (0); ' id= ' Next ' > Next </a> '). Append (" & nbsp; "); }else{ & nbSp; sb.append ("next Page"). Append (" "); } 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/selectuserlist.do?currentpage=" +current+ ' &type=1 '; }) $ ("#pre" ). Click (function () { var current=$ ("#current"). HTML (); window.location.href= "${app}/usercontroller/selectuserlist.do?currentpage=" + current+ ' &type=2 '; })
Pageutil Sub-page