Module bus.pager

Class PageObject

java.lang.Object
org.miaixz.bus.pager.binding.PageObject

public abstract class PageObject extends Object
Utility class for handling pagination parameter objects. This class provides methods to extract pagination information from various parameter types, including Paging objects and objects that can be introspected via MyBatis's MetaObject.
Since:
Java 17+
Author:
Kimi Liu
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static Method
    The `getParameterMap` method of `jakarta.servlet.ServletRequest`, if available.
    protected static Boolean
    Indicates whether the application has access to `jakarta.servlet.ServletRequest`.
    protected static Map<String,String>
    A map storing parameter name mappings for pagination properties.
    protected static Class<?>
    The `jakarta.servlet.ServletRequest` class, if available.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> Page<T>
    getPageFromObject(Object params, boolean required)
    Extracts pagination parameters from an object and creates a Page instance.
    protected static Object
    getParamValue(org.apache.ibatis.reflection.MetaObject paramsObject, String paramName, boolean required)
    Retrieves a parameter value from a MetaObject.
    static void
    setParams(String params)
    Sets custom parameter name mappings for pagination properties.

    Methods inherited from class java.lang.Object

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

    • hasRequest

      protected static Boolean hasRequest
      Indicates whether the application has access to `jakarta.servlet.ServletRequest`.
    • requestClass

      protected static Class<?> requestClass
      The `jakarta.servlet.ServletRequest` class, if available.
    • getParameterMap

      protected static Method getParameterMap
      The `getParameterMap` method of `jakarta.servlet.ServletRequest`, if available.
    • PARAMS

      protected static Map<String,String> PARAMS
      A map storing parameter name mappings for pagination properties. Keys are common parameter names (e.g., "pageNo"), values are the actual property names.
  • Constructor Details

    • PageObject

      public PageObject()
  • Method Details

    • getPageFromObject

      public static <T> Page<T> getPageFromObject(Object params, boolean required)
      Extracts pagination parameters from an object and creates a Page instance. It supports Paging objects, `jakarta.servlet.ServletRequest` objects, and generic objects that can be introspected by MyBatis's MetaObject.
      Type Parameters:
      T - the type of elements in the paginated data
      Parameters:
      params - the parameter object from which to extract pagination information
      required - if true, throws a PageException if required pagination parameters are missing
      Returns:
      a Page object configured with the extracted parameters, or null if no pagination parameters are found and not required
      Throws:
      org.miaixz.bus.core.lang.exception.PageException - if `params` is null, or if required parameters are missing, or if pagination parameters are not valid numbers
    • getParamValue

      protected static Object getParamValue(org.apache.ibatis.reflection.MetaObject paramsObject, String paramName, boolean required)
      Retrieves a parameter value from a MetaObject.
      Parameters:
      paramsObject - the MetaObject representing the parameter object
      paramName - the name of the parameter to retrieve (e.g., "pageNo", "pageSize")
      required - if true, throws a PageException if the parameter is not found
      Returns:
      the value of the parameter, or null if not found and not required
      Throws:
      org.miaixz.bus.core.lang.exception.PageException - if the parameter is required but not found
    • setParams

      public static void setParams(String params)
      Sets custom parameter name mappings for pagination properties. The input string should be a semicolon, comma, or ampersand-separated list of key-value pairs, where keys are common parameter names and values are the actual property names. Example: "pageNo=pageNum;pageSize=limit"
      Parameters:
      params - a string containing custom parameter mappings