java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
java.util.ArrayList<E>
org.miaixz.bus.pager.Page<E>
- Type Parameters:
E- the type of elements in this page
- All Implemented Interfaces:
Closeable,Serializable,AutoCloseable,Cloneable,Iterable<E>,Collection<E>,List<E>,RandomAccess,SequencedCollection<E>
MyBatis paging object, supporting paginated queries and result set management. This class extends
ArrayList
to hold the paginated data and implements Closeable to manage the paging context.- Since:
- Java 17+
- Author:
- Kimi Liu
- See Also:
-
Field Summary
Fields inherited from class java.util.AbstractList
modCount -
Constructor Summary
ConstructorsConstructorDescriptionPage()Default constructor.Page(int[] rowBounds, boolean count) Constructs a Page object based on row bounds for pagination.Page(int pageNo, int pageSize) Constructs a Page object with specified page number and page size.Page(int pageNo, int pageSize, boolean count) Constructs a Page object with specified page number, page size, and whether to perform a count query. -
Method Summary
Modifier and TypeMethodDescriptionbooleanChecks if asynchronous count queries are enabled.asyncCount(boolean asyncCount) Sets whether asynchronous count queries are enabled.boundSqlInterceptor(BoundSqlBuilder boundSqlHandler) Sets the BoundSql interceptor.voidclose()Closes the Page object and clears the paging context.Sets whether a count query should be executed.countColumn(String columnName) Specifies the column name for the count query.Disables asynchronous count queries.longExecutes a count query.<E> Page<E> doSelectPage(Querying select) Executes a paginated query.<E> Paginating<E> doSelectPageInfo(Querying select) Executes a paginated query and returns aPaginatingobject.<E> Serialize<E> doSelectPageSerializable(Querying select) Executes a paginated query and returns aSerializeobject.Enables asynchronous count queries.Retrieves whether asynchronous count queries are enabled.Retrieves the BoundSql interceptor.Retrieves the column name used for the count query.Retrieves the dialect class used for pagination.longRetrieves the ending row position.Retrieves whether to retain the order by clause in the count query.Retrieves whether to retain the order by clause of sub-queries in the count query.Retrieves the order by clause.intRetrieves the current page number.intgetPages()Retrieves the total number of pages.intRetrieves the page size.Retrieves the state of the pageSizeZero switch.Retrieves the state of the pagination reasonableness switch.Retrieves the paginated result set.Retrieves the stack trace where this Page object was created.longRetrieves the starting row position.longgetTotal()Retrieves the total number of records.booleanisCount()Checks if a count query should be executed.booleanChecks if only ordering should be applied without pagination.booleanChecks if the order by clause should be retained in the count query.keepOrderBy(boolean keepOrderBy) Sets whether to retain the order by clause in the count query.booleanChecks if the order by clause of sub-queries should be retained in the count query.keepSubSelectOrderBy(boolean keepSubSelectOrderBy) Sets whether to retain the order by clause of sub-queries in the count query.pageNo(int pageNo) Sets the page number.pageSize(int pageSize) Sets the page size.pageSizeZero(Boolean pageSizeZero) Sets the pageSizeZero switch.reasonable(Boolean reasonable) Sets the pagination reasonableness switch.voidsetAsyncCount(Boolean asyncCount) Sets whether asynchronous count queries are enabled.voidsetBoundSqlInterceptor(BoundSqlBuilder boundSqlHandler) Sets the BoundSql interceptor.setCount(boolean count) Sets whether a count query should be executed.voidsetCountColumn(String countColumn) Sets the column name for the count query, including SQL injection validation.voidsetDialectClass(String dialectClass) Sets the dialect class used for pagination.setEndRow(long endRow) Sets the ending row position.setKeepOrderBy(Boolean keepOrderBy) Sets whether to retain the order by clause in the count query.voidsetKeepSubSelectOrderBy(Boolean keepSubSelectOrderBy) Sets whether to retain the order by clause of sub-queries in the count query.<E> Page<E> setOrderBy(String orderBy) Sets the order by clause.voidsetOrderByOnly(boolean orderByOnly) Sets whether only ordering should be applied without pagination.setPageNo(int pageNo) Sets the page number, with support for reasonableness handling.setPages(int pages) Sets the total number of pages.setPageSize(int pageSize) Sets the page size.setPageSizeZero(Boolean pageSizeZero) Sets the pageSizeZero switch.setReasonable(Boolean reasonable) Sets the pagination reasonableness switch.setStartRow(long startRow) Sets the starting row position.voidsetTotal(long total) Sets the total number of records and calculates the total number of pages.<E> Page<E> setUnsafeOrderBy(String orderBy) Sets the order by clause unsafely.Converts the current Page object to aPaginatingobject.<T> Paginating<T> toPageInfo(org.miaixz.bus.core.center.function.FunctionX<E, T> function) Converts the paginated data and returns aPaginatingobject.Converts the current Page object to aSerializeobject.<T> Serialize<T> toPageSerializable(org.miaixz.bus.core.center.function.FunctionX<E, T> function) Converts the paginated data and returns aSerializeobject.toString()Returns a string representation of the Page object.Specifies the pagination implementation to use.Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, addFirst, addLast, clear, clone, contains, ensureCapacity, equals, forEach, get, getFirst, getLast, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeFirst, removeIf, removeLast, removeRange, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray, trimToSizeMethods inherited from class java.util.AbstractCollection
containsAllMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, stream, toArrayMethods inherited from interface java.util.List
containsAll, reversed
-
Constructor Details
-
Page
public Page()Default constructor. -
Page
public Page(int pageNo, int pageSize) Constructs a Page object with specified page number and page size.- Parameters:
pageNo- the page number (starts from 1)pageSize- the size of the page
-
Page
public Page(int pageNo, int pageSize, boolean count) Constructs a Page object with specified page number, page size, and whether to perform a count query.- Parameters:
pageNo- the page number (starts from 1)pageSize- the size of the pagecount- true to perform a count query, false otherwise
-
Page
public Page(int[] rowBounds, boolean count) Constructs a Page object based on row bounds for pagination.- Parameters:
rowBounds- an array containing row bounds, where index 0 is offset and index 1 is limitcount- true to perform a count query, false otherwise
-
-
Method Details
-
getStackTrace
Retrieves the stack trace where this Page object was created.- Returns:
- the stack trace information
-
getResult
Retrieves the paginated result set.- Returns:
- a list of paginated data
-
getPages
public int getPages()Retrieves the total number of pages.- Returns:
- the total number of pages
-
setPages
Sets the total number of pages.- Parameters:
pages- the total number of pages- Returns:
- the current Page object
-
getEndRow
public long getEndRow()Retrieves the ending row position.- Returns:
- the ending row position
-
setEndRow
Sets the ending row position.- Parameters:
endRow- the ending row position- Returns:
- the current Page object
-
getPageNo
public int getPageNo()Retrieves the current page number.- Returns:
- the current page number
-
setPageNo
Sets the page number, with support for reasonableness handling. If reasonableness is enabled and pageNo is less than or equal to 0, it will be set to 1.- Parameters:
pageNo- the page number- Returns:
- the current Page object
-
getPageSize
public int getPageSize()Retrieves the page size.- Returns:
- the page size
-
setPageSize
Sets the page size.- Parameters:
pageSize- the page size- Returns:
- the current Page object
-
getStartRow
public long getStartRow()Retrieves the starting row position.- Returns:
- the starting row position
-
setStartRow
Sets the starting row position.- Parameters:
startRow- the starting row position- Returns:
- the current Page object
-
getTotal
public long getTotal()Retrieves the total number of records.- Returns:
- the total number of records
-
setTotal
public void setTotal(long total) Sets the total number of records and calculates the total number of pages.- Parameters:
total- the total number of records
-
getReasonable
Retrieves the state of the pagination reasonableness switch.- Returns:
- the state of the reasonableness switch
-
setReasonable
Sets the pagination reasonableness switch. If reasonableness is enabled and the current page number is less than or equal to 0, it will be set to 1.- Parameters:
reasonable- the reasonableness switch- Returns:
- the current Page object
-
getPageSizeZero
Retrieves the state of the pageSizeZero switch.- Returns:
- the state of the pageSizeZero switch
-
setPageSizeZero
Sets the pageSizeZero switch. If true, and pageSize is 0, all results are returned without pagination.- Parameters:
pageSizeZero- true if pageSize 0 should return all results, false otherwise- Returns:
- the current Page object
-
getOrderBy
Retrieves the order by clause.- Returns:
- the order by clause
-
setOrderBy
Sets the order by clause.- Type Parameters:
E- the type of elements in this page- Parameters:
orderBy- the order by clause- Returns:
- the current Page object
-
setUnsafeOrderBy
Sets the order by clause unsafely. This method does not perform SQL injection checks, so ensure theorderByparameter is safe.- Type Parameters:
E- the type of elements in this page- Parameters:
orderBy- the order by clause- Returns:
- the current Page object
-
isOrderByOnly
public boolean isOrderByOnly()Checks if only ordering should be applied without pagination.- Returns:
- true if only ordering should be applied, false otherwise
-
setOrderByOnly
public void setOrderByOnly(boolean orderByOnly) Sets whether only ordering should be applied without pagination.- Parameters:
orderByOnly- true if only ordering should be applied, false otherwise
-
getDialectClass
Retrieves the dialect class used for pagination.- Returns:
- the dialect class name
-
setDialectClass
Sets the dialect class used for pagination.- Parameters:
dialectClass- the dialect class name
-
getKeepOrderBy
Retrieves whether to retain the order by clause in the count query.- Returns:
- true if the order by clause should be retained, false otherwise
-
setKeepOrderBy
Sets whether to retain the order by clause in the count query.- Parameters:
keepOrderBy- true if the order by clause should be retained, false otherwise- Returns:
- the current Page object
-
getKeepSubSelectOrderBy
Retrieves whether to retain the order by clause of sub-queries in the count query.- Returns:
- true if the order by clause of sub-queries should be retained, false otherwise
-
setKeepSubSelectOrderBy
Sets whether to retain the order by clause of sub-queries in the count query.- Parameters:
keepSubSelectOrderBy- true if the order by clause of sub-queries should be retained, false otherwise
-
getAsyncCount
Retrieves whether asynchronous count queries are enabled.- Returns:
- true if asynchronous count queries are enabled, false otherwise
-
setAsyncCount
Sets whether asynchronous count queries are enabled.- Parameters:
asyncCount- true to enable asynchronous count queries, false otherwise
-
using
Specifies the pagination implementation to use.- Parameters:
dialect- the dialect class name, can use aliases registered inPageAutoDialectlike "mysql", "oracle"- Returns:
- the current Page object
-
isCount
public boolean isCount()Checks if a count query should be executed.- Returns:
- true if a count query should be executed, false otherwise
-
setCount
Sets whether a count query should be executed.- Parameters:
count- true to execute a count query, false otherwise- Returns:
- the current Page object
-
pageNo
Sets the page number. If reasonableness is enabled and pageNo is less than or equal to 0, it will be set to 1.- Parameters:
pageNo- the page number- Returns:
- the current Page object
-
pageSize
Sets the page size.- Parameters:
pageSize- the page size- Returns:
- the current Page object
-
count
Sets whether a count query should be executed.- Parameters:
count- true to execute a count query, false otherwise- Returns:
- the current Page object
-
reasonable
Sets the pagination reasonableness switch.- Parameters:
reasonable- the pagination reasonableness switch- Returns:
- the current Page object
-
pageSizeZero
Sets the pageSizeZero switch.- Parameters:
pageSizeZero- true if pageSize 0 should return all results, false otherwise- Returns:
- the current Page object
-
boundSqlInterceptor
Sets the BoundSql interceptor.- Parameters:
boundSqlHandler- the BoundSql interceptor- Returns:
- the current Page object
-
countColumn
Specifies the column name for the count query.- Parameters:
columnName- the column name- Returns:
- the current Page object
-
keepOrderBy
Sets whether to retain the order by clause in the count query.- Parameters:
keepOrderBy- true if the order by clause should be retained, false otherwise- Returns:
- the current Page object
-
keepOrderBy
public boolean keepOrderBy()Checks if the order by clause should be retained in the count query.- Returns:
- true if the order by clause should be retained, false otherwise
-
keepSubSelectOrderBy
Sets whether to retain the order by clause of sub-queries in the count query.- Parameters:
keepSubSelectOrderBy- true if the order by clause of sub-queries should be retained, false otherwise- Returns:
- the current Page object
-
keepSubSelectOrderBy
public boolean keepSubSelectOrderBy()Checks if the order by clause of sub-queries should be retained in the count query.- Returns:
- true if the order by clause of sub-queries should be retained, false otherwise
-
asyncCount
Sets whether asynchronous count queries are enabled.- Parameters:
asyncCount- true to enable asynchronous count queries, false otherwise- Returns:
- the current Page object
-
enableAsyncCount
Enables asynchronous count queries.- Returns:
- the current Page object
-
disableAsyncCount
Disables asynchronous count queries.- Returns:
- the current Page object
-
asyncCount
public boolean asyncCount()Checks if asynchronous count queries are enabled.- Returns:
- true if asynchronous count queries are enabled, false otherwise
-
toPageInfo
Converts the current Page object to aPaginatingobject.- Returns:
- a
Paginatingobject
-
toPageInfo
Converts the paginated data and returns aPaginatingobject.- Type Parameters:
T- the type of the converted data elements- Parameters:
function- the data conversion function- Returns:
- a
Paginatingobject with converted data
-
toPageSerializable
Converts the current Page object to aSerializeobject.- Returns:
- a
Serializeobject
-
toPageSerializable
public <T> Serialize<T> toPageSerializable(org.miaixz.bus.core.center.function.FunctionX<E, T> function) Converts the paginated data and returns aSerializeobject.- Type Parameters:
T- the type of the converted data elements- Parameters:
function- the data conversion function- Returns:
- a
Serializeobject with converted data
-
doSelectPage
Executes a paginated query.- Type Parameters:
E- the type of elements in this page- Parameters:
select- the query object- Returns:
- the current Page object
-
doSelectPageInfo
Executes a paginated query and returns aPaginatingobject.- Type Parameters:
E- the type of elements in this page- Parameters:
select- the query object- Returns:
- a
Paginatingobject
-
doSelectPageSerializable
Executes a paginated query and returns aSerializeobject.- Type Parameters:
E- the type of elements in this page- Parameters:
select- the query object- Returns:
- a
Serializeobject
-
doCount
Executes a count query.- Parameters:
select- the query object- Returns:
- the total number of records
-
getCountColumn
Retrieves the column name used for the count query.- Returns:
- the count query column name
-
setCountColumn
Sets the column name for the count query, including SQL injection validation.- Parameters:
countColumn- the column name
-
getBoundSqlInterceptor
Retrieves the BoundSql interceptor.- Returns:
- the BoundSql interceptor
-
setBoundSqlInterceptor
Sets the BoundSql interceptor.- Parameters:
boundSqlHandler- the BoundSql interceptor
-
toString
Returns a string representation of the Page object.- Overrides:
toStringin classAbstractCollection<E>- Returns:
- a string representation of the object
-
close
public void close()Closes the Page object and clears the paging context. This method is part of theCloseableinterface implementation.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-