Importjava.io.UnsupportedEncodingException;ImportJava.net.URLEncoder;ImportJava.util.Iterator;Importjava.util.List;ImportNet.sf.json.JSONObject;/*** Pagination class *@authorRubekid * *@param<T>*/ Public classPage<t>extendsQueryParameter { Public Static Final intPage_size = 20; Privatelist<t> result =NULL; Private LongTotalCount =-1; PrivateJsonobject Queryparams =NewJsonobject (); PublicPage () {setpagesize (page_size); } PublicPage (intpageSize) {setpagesize (pageSize); } PublicPage (intPageSize,BooleanAutocount) {setpagesize (pageSize); This. Autocount =Autocount; } /*** Get Reverse sort *@return */ PublicString Getinverseorder () {if(Order.endswith ("desc")){ return"ASC"; } return"Desc"; } PublicList<t>GetResult () {returnresult; } Public voidSetresult (list<t>result) { This. result =result; } Public LongGettotalcount () {return This. TotalCount; } Public voidSettotalcount (Longtotalcount) { This. TotalCount =TotalCount; } Public Longgettotalpages () {if(TotalCount < 0){ return-1; } LongCount = TotalCount/pageSize; if(totalcount% PageSize > 0) {Count++; } returncount; } Public BooleanIshasnext () {return(PageNo + 1 <=gettotalpages ()); } Public intGetnextpage () {if(Ishasnext ()) {returnPageNo + 1; } return This. PageNo; } Public BooleanIshaspre () {return(PageNo-1 >= 1); } Public intGetprepage () {if(Ishaspre ()) {returnPageNo-1; } returnPageNo; } Public voidAddqueryparam (String key, Object value) {queryparams.put (key, value); } @SuppressWarnings ("Unchecked") PublicString getquerystring ()throwsunsupportedencodingexception{String Result= ""; for(Iterator<string> Iterator =Queryparams.keys (); Iterator.hasnext ();) {String key=Iterator.next (); Result+ = key + "=" + Urlencoder.encode (queryparams.getstring (key), "Utf-8") + "&"; } if(Result.length () > 0) {result= result.substring (0, Result.length ()-1); } returnresult; } PublicString getqueryparamstring () {returnqueryparams.tostring (); } Public voidsetquerystring (String queryString) {queryparams=Jsonobject.fromobject (queryString); } Publicjsonobject GetQueryParams () {returnQueryparams; }}
Java Paging Class page