First, create a paging universal class
1 PackageCom.dkyw.util;2 3 Importjava.util.List;4 5 Public classPage<t> {6 Private intTotal//Total Pages7 Private intPageIndex;//Current page number8 Private intPageSize;//size per page9 Privatelist<t> rows;//the collection object for the current pageTen One Public intgettotal () { A returnTotal ; - } - Public voidSettotal (intTotal ) { the This. Total =Total ; - } - Public intGetpageindex () { - returnPageIndex; + } - Public voidSetpageindex (intPageIndex) { + This. PageIndex =PageIndex; A } at Public intgetpagesize () { - returnpageSize; - } - Public voidSetPageSize (intpageSize) { - This. pageSize =pageSize; - } in PublicList<t>getRows () { - returnrows; to } + Public voidSetrows (list<t>rows) { - This. rows =rows; the } * $}
Second, serivice the collection information returned by the package is a collection of page objects
PublicPage<template> Gettemplateforpage (intPageIndex,intpageSize) { intPagestart = (pageIndex-1) *pageSize; List<Template> list =templatedao.getforpage (pagestart,pagesize); for(template template:list) {Template.setdatasource (Datasourcedao.getbyid (template. Get DataSourceId ())); } Page<Template> page =NewPage<template>(); Page.setpageindex (PageIndex); Page.setpagesize (pageSize); Page.setrows (list); intCount =Templatedao.getcount (); Page.settotal ((int) Math.ceil (count*1.0/pageSize)); returnpage; }
Iii. handling after return to the front end
/*Get Paging Data*/ functionGettemplateinfoforpage (pageindex,pagesize) {$.ajax ({URL:"Gettemplateinfoforpage.action",//the server URL to requestdata: {"PageIndex": PageIndex,"PageSize":p Agesize}, Async:true,//is an asynchronous requestType: "POST",//Request mode is postSuccess:function(Result) {Console.log ("Paging Data"); Result=json.parse (Result); var_length = 3;//Maximum Page 3 //splicing pagination if(result[0].total<_length) { $("#pageInfo"). HTML (""); varStart = (pageIndex-1) >0? PageIndex-1: PageIndex; varEnd = (pageindex+1) <=result[0].total? Pageindex+1: PageIndex; $("#pageInfo"). Append ("<li><a onclick= ' Gettemplateinfoforpage (" +start + "," +pagesize+ ") ' aria-label= ' Previous ' ><span aria-hidden= ' true ' >«</span></a></li> '); for(var int= 1;int< result[0].total+1;int++) { if(int==PageIndex) { $("#pageInfo"). Append ("<li class= ' active ' ><a onclick= ' gettemplateinfoforpage (" +int+ "," +pagesize+ ") ' > ' +int+ "</a></li>"); }Else{ $("#pageInfo"). Append ("<li><a onclick= ' gettemplateinfoforpage (" +int+ "," +pagesize+ ") ' > ' +int+ "</a></li>"); } } $("#pageInfo"). Append ("<li><a onclick= ' Gettemplateinfoforpage (" +end+ "," +pagesize+ ") ' aria-label= ' Next ' ><span aria-hidden= ' true ' >»</span></a></li> ') }Else{ Debugger; $("#pageInfo"). HTML (""); varPagearr=NewArray (); //4 if(Pageindex+math.floor (_LENGTH/2) <= Result[0].total&&pageindex-math.floor (_LENGTH/2) > 0) {//The current page does not exceed the total number of pages for(vari = 0; i < _length; i++) {Pagearr[i]= Pageindex-math.floor (_LENGTH/2) + i; } }Else if(Pageindex<=math.floor (_LENGTH/2)) { for(varInt2 = 1; Int2 < _length+1; int2++) {Pagearr.push (Int2); } //Pagearr = [1,2,3,4,5,6,7,8,9];}Else{ for(vari = 0; i < _length; i++){ //8Pagearr[i] = result[0].total-(_length-1) +i; } } varStart = (pageIndex-1) >0? PageIndex-1: PageIndex; varEnd = (pageindex+1) <=result[0].total? Pageindex+1: PageIndex; $("#pageInfo"). Append ("<li><a onclick= ' Gettemplateinfoforpage (" +start + "," +pagesize+ ") ' aria-label= ' Previous ' ><span aria-hidden= ' true ' >«</span></a></li> '); for(var int= Pagearr[0];int<= Pagearr[pagearr.length-1];int++) { if(int==PageIndex) { $("#pageInfo"). Append ("<li class= ' active ' ><a onclick= ' gettemplateinfoforpage (" +int+ "," +pagesize+ ") ' > ' +int+ "</a></li>"); }Else{ $("#pageInfo"). Append ("<li><a onclick= ' gettemplateinfoforpage (" +int+ "," +pagesize+ ") ' > ' +int+ "</a></li>"); } } $("#pageInfo"). Append ("<li><a onclick= ' Gettemplateinfoforpage (" +end+ "," +pagesize+ ") ' aria-label= ' Next ' ><span aria-hidden= ' true ' >»</span></a></li> ') } $("#tbody"). HTML (""); $.each (result[0].rows,function(Index,item) {Console.log (item); $("#tbody"). Append ("<tr onclick= ' showtemplate (" +item.id+ ", \" "+item.echarttype+" \ "); ' > "+" <td><input type= ' checkbox ' name= ' Deletecheck ' data-id= "+item.id+" data-type= "+e charttypemap[item.echarttype]+ "></td>" + "<td>" +item.id+ "</td>" + "<td>" +item.templatename+ "</td>" + "<td>" +item.datasource.dat Aname+ "</td>" + "<td>" +getecharttype (item.echarttype) + "</td>" + "<td>" +getechartmethod (item.echartmethod) + "</td>" + "<td>" +item.ta Blename+ "</td>" + "<td><button type= ' button ' class= ' btn btn-default ' onclick= ' upd Atetemplate ("+item.id+ "," +item.datasource.id+ ", \" "+item.templatename+" \ ", \" "+item.echarttype+" \ ", \" "+item.rowfield+" \ ", \" "+ Item.tablename+ "\"); ' > Modify </button></td> "+" </tr> "); }); } }) }
Java Paging General Chapter