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 | 总页数
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
ConstructorsConstructorDescriptionPageInfo(int page, int size, long total, int totalPages) Compact constructor with calculation 带计算的紧凑构造函数 -
Method Summary
Modifier and TypeMethodDescriptionstatic PageInfoempty()Create empty page info 创建空分页信息final booleanIndicates whether some other object is "equal to" this one.static PageInfofrom(PageRequest request, long total) Create from page request 从分页请求创建intGet current page actual size 获取当前页实际大小longGet end offset for current page 获取当前页结束位置intGet next page number 获取下一页页码intGet offset for SQL 获取SQL偏移量intGet previous page number 获取上一页页码final inthashCode()Returns a hash code value for this object.booleanhasNext()Check if has next page 检查是否有下一页booleanCheck if has previous page 检查是否有上一页booleanisEmpty()Check if empty 检查是否为空booleanisFirst()Check if first page 检查是否第一页booleanisLast()Check if last page 检查是否最后一页static PageInfoof(int page, int size, long total) Create page info 创建分页信息intpage()Returns the value of thepagerecord component.intsize()Returns the value of thesizerecord component.final StringtoString()Returns a string representation of this record class.longtotal()Returns the value of thetotalrecord component.intReturns the value of thetotalPagesrecord component.
-
Constructor Details
-
PageInfo
public PageInfo(int page, int size, long total, int totalPages) Compact constructor with calculation 带计算的紧凑构造函数
-
-
Method Details
-
of
Create page info 创建分页信息- Parameters:
page- the page number | 页码size- the page size | 页大小total- the total count | 总数- Returns:
- the page info | 分页信息
-
from
Create from page request 从分页请求创建- Parameters:
request- the page request | 分页请求total- the total count | 总数- Returns:
- the page info | 分页信息
-
empty
-
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
-
hashCode
-
equals
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 thecomparemethod from their corresponding wrapper classes. -
page
-
size
-
total
-
totalPages
public int totalPages()Returns the value of thetotalPagesrecord component.- Returns:
- the value of the
totalPagesrecord component
-