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