Threadlocal Classic Pagination

Source: Internet
Author: User

Package Com.netease.live.admin.util;import com.netease.live.common.util.constant;/** * * @author Bjliuzezhou * @ Description parameters required to use ThreadLocal to encapsulate paging * @date July 1, 2016 */public class Systemcontext {//Current page private static threadlocal& lt;integer> currentpage = new threadlocal<integer> ();//Total number of pages private static threadlocal<integer> TotalPages = new threadlocal<integer> ();//Start Data location private static threadlocal<integer> OffSet = new Threadlocal<integer> ();//The number of entries in the total record private static threadlocal<integer> RecordCount = new threadlocal< Integer> ();      Each page shows the number of private static threadlocal<integer> pageSize = new threadlocal<integer> (); /* * Currentpage:get, set, remove */public static int getcurrentpage () {Integer CP = Currentpage.get (); if (CP = = null) {R Eturn 0;} return CP;} public static void Setcurrentpage (int currentpage) {int validpage = currentpage > 0? currentpage:1;validpage = valid Page < Gettotalpages ()? Validpage:gettotalpages (); SystemContext.currentPage.set (validpage);} public static void Removecurrentpage () {currentpage.remove ();}      /* * Totalpages:get, set, remove */public static int gettotalpages () {Integer TP = Totalpages.get ();      if (TP = = null) {return 0;  } return TP;    } public static void Caltotalpages () {int totalpages = (GetRecordCount () + getpagesize ()-1)/getpagesize ();  SystemContext.totalPages.set (TotalPages);  } public static void Removetotalpages () {totalpages.remove ();      }/* * Offset:get, set, remove */public static int GetOffset () {Integer os =offset.get ();      if (OS = = null) {return 0;  } return OS;  } public static void Caloffset () {int offset = (Getcurrentpage ()-1) * getpagesize (); int validoffset = offset > 0? offset:0;  SystemContext.offSet.set (Validoffset);}  public static void Removeoffset () {offset.remove (); }/* * Recordcount:get, set, remove */public static int GetRecordCount () {Integer rc = REcordcount.get (); if (rc = = null) {return 0;} return RC;} public static void Setrecordcount (int recordCount) {SystemContext.recordCount.set (recordCount);} public static void Removerecordcount () {recordcount.remove ();}/* Pagesize:get, set, remove */public static int GETPA Gesize () {Integer PS = Pagesize.get (); if (PS = = null) {return 0;} return PS;} public static void SetPageSize (int pageSize) {SystemContext.pageSize.set (pageSize);} public static void Removepagesize () {pagesize.remove ();} public static void Pagefilter (int recordcount,int pagesize,int currentpage) {//records total number of bars Systemcontext.setrecordcount (reco Rdcount); Systemcontext.setpagesize (Constant.page_count); Systemcontext.caltotalpages (); Systemcontext.setcurrentpage (currentpage);    Systemcontext.caloffset (); }}

The total number of pages is set through Pagefilter, the number of bars displayed per page, the current page count, total record bars, and the offset starting position when the database is passed in.

Threadlocal Classic Pagination

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.