Java Paging Class page

Source: Internet
Author: User

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

Related Article

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: info-contact@alibabacloud.com 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.