Record Class PageInfo

java.lang.Object
java.lang.Record
cloud.opencode.base.web.page.PageInfo
Record Components:
page - the page number (1-based) | 页码(从1开始)
size - the page size | 页大小
total - the total count | 总数
totalPages - the total pages | 总页数

public record PageInfo(int page, int size, long total, int totalPages) extends Record
Page Info 分页信息

Contains pagination metadata.

包含分页元数据。

Features | 主要功能:

  • Automatic total pages calculation - 自动计算总页数
  • Page navigation queries (hasNext, hasPrevious) - 分页导航查询
  • SQL offset computation - SQL 偏移量计算
  • Current page size calculation - 当前页大小计算

Usage Examples | 使用示例:

// Create page info
PageInfo info = PageInfo.of(1, 10, 100);

// Query navigation
boolean hasNext = info.hasNext(); // true
int totalPages = info.totalPages(); // 10
int offset = info.getOffset(); // 0

Security | 安全性:

  • Thread-safe: Yes (immutable record) - 线程安全: 是(不可变记录)
  • Null-safe: Yes (values clamped to valid ranges) - 空值安全: 是(值限制在有效范围内)
Since:
JDK 25, opencode-base-web V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    PageInfo(int page, int size, long total, int totalPages)
    Compact constructor with calculation 带计算的紧凑构造函数
  • Method Summary

    Modifier and Type
    Method
    Description
    static PageInfo
    Create empty page info 创建空分页信息
    final boolean
    Indicates whether some other object is "equal to" this one.
    static PageInfo
    from(PageRequest request, long total)
    Create from page request 从分页请求创建
    int
    Get current page actual size 获取当前页实际大小
    long
    Get end offset for current page 获取当前页结束位置
    int
    Get next page number 获取下一页页码
    int
    Get offset for SQL 获取SQL偏移量
    int
    Get previous page number 获取上一页页码
    final int
    Returns a hash code value for this object.
    boolean
    Check if has next page 检查是否有下一页
    boolean
    Check if has previous page 检查是否有上一页
    boolean
    Check if empty 检查是否为空
    boolean
    Check if first page 检查是否第一页
    boolean
    Check if last page 检查是否最后一页
    static PageInfo
    of(int page, int size, long total)
    Create page info 创建分页信息
    int
    Returns the value of the page record component.
    int
    Returns the value of the size record component.
    final String
    Returns a string representation of this record class.
    long
    Returns the value of the total record component.
    int
    Returns the value of the totalPages record component.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • PageInfo

      public PageInfo(int page, int size, long total, int totalPages)
      Compact constructor with calculation 带计算的紧凑构造函数
  • Method Details

    • of

      public static PageInfo of(int page, int size, long total)
      Create page info 创建分页信息
      Parameters:
      page - the page number | 页码
      size - the page size | 页大小
      total - the total count | 总数
      Returns:
      the page info | 分页信息
    • from

      public static PageInfo from(PageRequest request, long total)
      Create from page request 从分页请求创建
      Parameters:
      request - the page request | 分页请求
      total - the total count | 总数
      Returns:
      the page info | 分页信息
    • empty

      public static PageInfo empty()
      Create empty page info 创建空分页信息
      Returns:
      the page info | 分页信息
    • hasNext

      public boolean hasNext()
      Check if has next page 检查是否有下一页
      Returns:
      true if has next | 如果有下一页返回true
    • hasPrevious

      public boolean hasPrevious()
      Check if has previous page 检查是否有上一页
      Returns:
      true if has previous | 如果有上一页返回true
    • isFirst

      public boolean isFirst()
      Check if first page 检查是否第一页
      Returns:
      true if first | 如果是第一页返回true
    • isLast

      public boolean isLast()
      Check if last page 检查是否最后一页
      Returns:
      true if last | 如果是最后一页返回true
    • isEmpty

      public boolean isEmpty()
      Check if empty 检查是否为空
      Returns:
      true if empty | 如果为空返回true
    • getOffset

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

      public int getNextPage()
      Get next page number 获取下一页页码
      Returns:
      the next page number | 下一页页码
    • getPreviousPage

      public int getPreviousPage()
      Get previous page number 获取上一页页码
      Returns:
      the previous page number | 上一页页码
    • getEndOffset

      public long getEndOffset()
      Get end offset for current page 获取当前页结束位置
      Returns:
      the end offset | 结束偏移量
    • getCurrentPageSize

      public int getCurrentPageSize()
      Get current page actual size 获取当前页实际大小
      Returns:
      the current page size | 当前页大小
    • 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. All components in this record class 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
    • total

      public long total()
      Returns the value of the total record component.
      Returns:
      the value of the total record component
    • totalPages

      public int totalPages()
      Returns the value of the totalPages record component.
      Returns:
      the value of the totalPages record component