Record Class PageRequest

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

public record PageRequest(long page, long size, Sort sort) extends Record
PageRequest - Immutable pagination request with sorting 分页请求 - 带排序的不可变分页请求

Represents a request for a specific page of data with optional sorting. Page numbering is 1-based. Compatible with Spring Data Pageable semantics but has no dependency on Spring Data Commons.

表示带可选排序的特定分页数据请求。页码从 1 开始。 与 Spring Data Pageable 语义兼容,但不依赖 Spring Data Commons。

Usage Examples | 使用示例:

PageRequest req = PageRequest.of(1, 20, Sort.by("name"));
PageRequest next = req.next();
long offset = req.getOffset();  // (page - 1) * size

Features | 主要功能:

  • Immutable pagination request with sorting - 带排序的不可变分页请求
  • 1-based page numbering - 基于1的页码
  • Navigation methods: next(), previous(), first() - 导航方法: next()、previous()、first()

Security | 安全性:

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

    • PageRequest

      public PageRequest(long page, long size, Sort sort)
      Creates an instance of a PageRequest record class.
      Parameters:
      page - the value for the page record component
      size - the value for the size record component
      sort - the value for the sort record component
  • Method Details

    • of

      public static PageRequest of(long page, long size)
    • of

      public static PageRequest of(long page, long size, Sort sort)
    • ofSize

      public static PageRequest ofSize(long size)
    • getOffset

      public long getOffset()
    • isFirst

      public boolean isFirst()
    • next

      public PageRequest next()
    • previous

      public PageRequest previous()
    • first

      public PageRequest first()
    • withSort

      public PageRequest withSort(Sort newSort)
    • withPage

      public PageRequest withPage(long newPage)
    • toPage

      public <T> Page<T> toPage()
      Creates an empty Page matching this request's page number and size. 创建一个与此请求的页码和页大小匹配的空 Page
      Type Parameters:
      T - the record type | 记录类型
      Returns:
      an empty Page | 空分页对象
      Since:
      JDK 25, opencode-base-core V1.0.3
    • toString

      public 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 long page()
      Returns the value of the page record component.
      Returns:
      the value of the page record component
    • size

      public long 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