Record Class PageRequest

java.lang.Object
java.lang.Record
cloud.opencode.base.web.page.PageRequest
Record Components:
page - the page number (1-based) | 页码(从1开始)
size - the page size | 页大小
sort - the sort criteria | 排序条件

public record PageRequest(int page, int size, Sort sort) extends Record
Page Request 分页请求

Standard pagination request parameters.

标准分页请求参数。

Features | 主要功能:

  • 1-based page numbering with validation - 基于 1 的页码编号并带验证
  • Sort criteria support - 排序条件支持
  • Page navigation (next, previous, first) - 分页导航(下一页、上一页、第一页)
  • SQL offset calculation - SQL 偏移量计算

Usage Examples | 使用示例:

// Simple page request
PageRequest request = PageRequest.of(1, 20);

// With sort
PageRequest request = PageRequest.of(1, 20, "name", "asc");

// Navigation
PageRequest next = request.next();
int offset = request.getOffset();

Security | 安全性:

  • Thread-safe: Yes (immutable record) - 线程安全: 是(不可变记录)
  • Null-safe: Yes (sort defaults to unsorted) - 空值安全: 是(排序默认为无排序)
Since:
JDK 25, opencode-base-web V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • PageRequest

      public PageRequest(int page, int size, Sort sort)
      Compact constructor with validation 带验证的紧凑构造函数
  • Method Details

    • of

      public static PageRequest of(int page, int size)
      Create page request 创建分页请求
      Parameters:
      page - the page number | 页码
      size - the page size | 页大小
      Returns:
      the request | 请求
    • of

      public static PageRequest of(int page, int size, Sort sort)
      Create page request with sort 创建带排序的分页请求
      Parameters:
      page - the page number | 页码
      size - the page size | 页大小
      sort - the sort criteria | 排序条件
      Returns:
      the request | 请求
    • of

      public static PageRequest of(int page, int size, String sortBy, String sortOrder)
      Create page request with sort string 创建带排序字符串的分页请求
      Parameters:
      page - the page number | 页码
      size - the page size | 页大小
      sortBy - the sort field | 排序字段
      sortOrder - the sort order (asc/desc) | 排序顺序
      Returns:
      the request | 请求
    • defaultRequest

      public static PageRequest defaultRequest()
      Get default page request 获取默认分页请求
      Returns:
      the request | 请求
    • first

      public static PageRequest first(int size)
      Get first page request 获取第一页请求
      Parameters:
      size - the page size | 页大小
      Returns:
      the request | 请求
    • getOffset

      public int getOffset()
      Get offset for SQL 获取SQL偏移量
      Returns:
      the offset | 偏移量
    • hasSort

      public boolean hasSort()
      Check if has sort 检查是否有排序
      Returns:
      true if has sort | 如果有排序返回true
    • next

      public PageRequest next()
      Get next page request 获取下一页请求
      Returns:
      the next page request | 下一页请求
    • previous

      public PageRequest previous()
      Get previous page request 获取上一页请求
      Returns:
      the previous page request | 上一页请求
    • first

      public PageRequest first()
      Get first page request 获取第一页请求
      Returns:
      the first page request | 第一页请求
    • withPage

      public PageRequest withPage(int newPage)
      With different page 使用不同的页码
      Parameters:
      newPage - the new page number | 新页码
      Returns:
      the new request | 新请求
    • withSize

      public PageRequest withSize(int newSize)
      With different size 使用不同的页大小
      Parameters:
      newSize - the new size | 新页大小
      Returns:
      the new request | 新请求
    • withSort

      public PageRequest withSort(Sort newSort)
      With different sort 使用不同的排序
      Parameters:
      newSort - the new sort | 新排序
      Returns:
      the new request | 新请求
    • sortAsc

      public PageRequest sortAsc(String property)
      With ascending sort 使用升序
      Parameters:
      property - the property | 属性
      Returns:
      the new request | 新请求
    • sortDesc

      public PageRequest sortDesc(String property)
      With descending sort 使用降序
      Parameters:
      property - the property | 属性
      Returns:
      the new request | 新请求
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • page

      public int page()
      Returns the value of the page record component.
      Returns:
      the value of the page record component
    • size

      public int size()
      Returns the value of the size record component.
      Returns:
      the value of the size record component
    • sort

      public Sort sort()
      Returns the value of the sort record component.
      Returns:
      the value of the sort record component