java.lang.Object
org.miaixz.bus.pager.binding.PageMethod
- Direct Known Subclasses:
PageContext
Provides basic pagination methods for configuring and managing MyBatis paginated queries. This class uses a
ThreadLocal to store and retrieve Page objects, allowing for easy management of pagination parameters
within a thread's execution context.- Since:
- Java 17+
- Author:
- Kimi Liu
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static booleanDefault setting for whether to execute a count query.protected static final ThreadLocal<Page> Stores the pagination parameters for the current thread. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidClears thePageobject from the current thread's context.static longExecutes a query to get the total count of records without actual pagination.static <T> Page<T> Retrieves thePageobject associated with the current thread.static <E> Page<E> offsetPage(int offset, int limit) Starts pagination based on an offset and limit, similar toRowBounds.static <E> Page<E> offsetPage(int offset, int limit, boolean count) Starts pagination based on an offset, limit, and whether to execute a count query.static voidSets the order by clause for the current pagination context.static voidsetLocalPage(Page page) Sets thePageobject for the current thread.protected static voidsetStaticProperties(Properties properties) Sets global static properties for the pagination plugin.static <E> Page<E> startPage(int pageNo, int pageSize) Starts pagination with a specified page number and page size.static <E> Page<E> startPage(int pageNo, int pageSize, boolean count) Starts pagination with a specified page number, page size, and whether to execute a count query.static <E> Page<E> Starts pagination with comprehensive control over page number, page size, count query execution, pagination reasonableness, and zero page size handling.static <E> Page<E> Starts pagination with a specified page number, page size, and order by clause.static <E> Page<E> Starts pagination based on the properties of a given parameter object.
-
Field Details
-
LOCAL_PAGE
Stores the pagination parameters for the current thread. -
DEFAULT_COUNT
protected static boolean DEFAULT_COUNTDefault setting for whether to execute a count query. Defaults to true.
-
-
Constructor Details
-
PageMethod
public PageMethod()
-
-
Method Details
-
getLocalPage
Retrieves thePageobject associated with the current thread.- Type Parameters:
T- the type of elements in the paginated data- Returns:
- the current Page object, or null if none is set for the current thread
-
setLocalPage
Sets thePageobject for the current thread.- Parameters:
page- the Page object to set
-
clearPage
public static void clearPage()Clears thePageobject from the current thread's context. -
count
Executes a query to get the total count of records without actual pagination.- Parameters:
select- theQueryingobject representing the query to be executed- Returns:
- the total number of records
-
startPage
Starts pagination based on the properties of a given parameter object. The parameter object is analyzed to extract page number, page size, and order by information.- Type Parameters:
E- the type of elements in the paginated data- Parameters:
params- the parameter object containing pagination details- Returns:
- a new
Pageobject configured with the extracted parameters
-
startPage
Starts pagination with a specified page number and page size. A count query will be executed by default.- Type Parameters:
E- the type of elements in the paginated data- Parameters:
pageNo- the page number (starts from 1)pageSize- the number of records per page- Returns:
- a new
Pageobject configured for pagination
-
startPage
Starts pagination with a specified page number, page size, and whether to execute a count query.- Type Parameters:
E- the type of elements in the paginated data- Parameters:
pageNo- the page number (starts from 1)pageSize- the number of records per pagecount- true to execute a count query, false otherwise- Returns:
- a new
Pageobject configured for pagination
-
startPage
Starts pagination with a specified page number, page size, and order by clause.- Type Parameters:
E- the type of elements in the paginated data- Parameters:
pageNo- the page number (starts from 1)pageSize- the number of records per pageorderBy- the order by clause for sorting- Returns:
- a new
Pageobject configured for pagination and sorting
-
startPage
public static <E> Page<E> startPage(int pageNo, int pageSize, boolean count, Boolean reasonable, Boolean pageSizeZero) Starts pagination with comprehensive control over page number, page size, count query execution, pagination reasonableness, and zero page size handling.- Type Parameters:
E- the type of elements in the paginated data- Parameters:
pageNo- the page number (starts from 1)pageSize- the number of records per pagecount- true to execute a count query, false otherwisereasonable- the reasonableness switch for pagination; if null, uses default configurationpageSizeZero- if true and pageSize is 0, all results are returned; if null, uses default configuration- Returns:
- a new
Pageobject configured for pagination
-
offsetPage
Starts pagination based on an offset and limit, similar toRowBounds. A count query will be executed by default.- Type Parameters:
E- the type of elements in the paginated data- Parameters:
offset- the starting offsetlimit- the maximum number of records to return- Returns:
- a new
Pageobject configured for pagination
-
offsetPage
Starts pagination based on an offset, limit, and whether to execute a count query.- Type Parameters:
E- the type of elements in the paginated data- Parameters:
offset- the starting offsetlimit- the maximum number of records to returncount- true to execute a count query, false otherwise- Returns:
- a new
Pageobject configured for pagination
-
orderBy
Sets the order by clause for the current pagination context. If aPageobject is already present in theThreadLocal, its order by property is updated. Otherwise, a newPageobject is created with only the order by clause set.- Parameters:
orderBy- the order by clause for sorting
-
setStaticProperties
Sets global static properties for the pagination plugin. This method is typically called during plugin initialization to configure default behaviors.- Parameters:
properties- the plugin configuration properties
-