Module bus.pager

Class PageMethod

java.lang.Object
org.miaixz.bus.pager.binding.PageMethod
Direct Known Subclasses:
PageContext

public abstract class PageMethod extends Object
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

    Fields
    Modifier and Type
    Field
    Description
    protected static boolean
    Default setting for whether to execute a count query.
    protected static final ThreadLocal<Page>
    Stores the pagination parameters for the current thread.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Clears the Page object from the current thread's context.
    static long
    count(Querying select)
    Executes a query to get the total count of records without actual pagination.
    static <T> Page<T>
    Retrieves the Page object associated with the current thread.
    static <E> Page<E>
    offsetPage(int offset, int limit)
    Starts pagination based on an offset and limit, similar to RowBounds.
    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 void
    orderBy(String orderBy)
    Sets the order by clause for the current pagination context.
    static void
    Sets the Page object for the current thread.
    protected static void
    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>
    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.
    static <E> Page<E>
    startPage(int pageNo, int pageSize, String orderBy)
    Starts pagination with a specified page number, page size, and order by clause.
    static <E> Page<E>
    startPage(Object params)
    Starts pagination based on the properties of a given parameter object.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • LOCAL_PAGE

      protected static final ThreadLocal<Page> LOCAL_PAGE
      Stores the pagination parameters for the current thread.
    • DEFAULT_COUNT

      protected static boolean DEFAULT_COUNT
      Default setting for whether to execute a count query. Defaults to true.
  • Constructor Details

    • PageMethod

      public PageMethod()
  • Method Details

    • getLocalPage

      public static <T> Page<T> getLocalPage()
      Retrieves the Page object 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

      public static void setLocalPage(Page page)
      Sets the Page object for the current thread.
      Parameters:
      page - the Page object to set
    • clearPage

      public static void clearPage()
      Clears the Page object from the current thread's context.
    • count

      public static long count(Querying select)
      Executes a query to get the total count of records without actual pagination.
      Parameters:
      select - the Querying object representing the query to be executed
      Returns:
      the total number of records
    • startPage

      public static <E> Page<E> startPage(Object params)
      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 Page object configured with the extracted parameters
    • startPage

      public static <E> Page<E> startPage(int pageNo, int pageSize)
      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 Page object configured for pagination
    • startPage

      public 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.
      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
      count - true to execute a count query, false otherwise
      Returns:
      a new Page object configured for pagination
    • startPage

      public static <E> Page<E> startPage(int pageNo, int pageSize, String orderBy)
      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 page
      orderBy - the order by clause for sorting
      Returns:
      a new Page object 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 page
      count - true to execute a count query, false otherwise
      reasonable - the reasonableness switch for pagination; if null, uses default configuration
      pageSizeZero - if true and pageSize is 0, all results are returned; if null, uses default configuration
      Returns:
      a new Page object configured for pagination
    • offsetPage

      public static <E> Page<E> offsetPage(int offset, int limit)
      Starts pagination based on an offset and limit, similar to RowBounds. A count query will be executed by default.
      Type Parameters:
      E - the type of elements in the paginated data
      Parameters:
      offset - the starting offset
      limit - the maximum number of records to return
      Returns:
      a new Page object configured for pagination
    • offsetPage

      public 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.
      Type Parameters:
      E - the type of elements in the paginated data
      Parameters:
      offset - the starting offset
      limit - the maximum number of records to return
      count - true to execute a count query, false otherwise
      Returns:
      a new Page object configured for pagination
    • orderBy

      public static void orderBy(String orderBy)
      Sets the order by clause for the current pagination context. If a Page object is already present in the ThreadLocal, its order by property is updated. Otherwise, a new Page object is created with only the order by clause set.
      Parameters:
      orderBy - the order by clause for sorting
    • setStaticProperties

      protected static void setStaticProperties(Properties properties)
      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