Record Class PageResult<T>
java.lang.Object
java.lang.Record
cloud.opencode.base.web.page.PageResult<T>
- Type Parameters:
T- the item type | 项类型- Record Components:
items- the items | 项列表pageInfo- the page info | 分页信息
Page Result
分页结果
Paginated list result.
分页列表结果。
Features | 主要功能:
- Immutable paginated result container - 不可变的分页结果容器
- Page navigation helpers (hasNext, hasPrevious) - 分页导航辅助方法
- Functional mapping support - 函数式映射支持
- Delegate methods for page metadata - 分页元数据的委托方法
Usage Examples | 使用示例:
// Create page result
PageResult<User> result = PageResult.of(userList, 100, 1, 10);
// Map items
PageResult<UserDTO> dtoResult = result.map(user -> toDTO(user));
// Check navigation
boolean hasMore = result.hasNext();
Security | 安全性:
- Thread-safe: Yes (immutable record) - 线程安全: 是(不可变记录)
- Null-safe: Yes (null items default to empty list) - 空值安全: 是(null 项默认为空列表)
- Since:
- JDK 25, opencode-base-web V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> PageResult<T> empty()Create empty result 创建空结果static <T> PageResult<T> empty(int page, int size) Create empty result with page info 创建带分页信息的空结果final booleanIndicates whether some other object is "equal to" this one.intgetCount()Get item count 获取项数量getFirst()Get first item 获取第一项getLast()Get last item 获取最后一项intgetPage()Get page number 获取页码intgetSize()Get page size 获取页大小longgetTotal()Get total count 获取总数intGet total pages 获取总页数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 检查是否最后一页items()Returns the value of theitemsrecord component.<R> PageResult<R> Map items to another type 将项映射为另一种类型<R> PageResult<R> Map entire list to another type 转换整个列表为另一种类型static <T> PageResult<T> Create page result 创建分页结果static <T> PageResult<T> of(List<T> items, long total, PageRequest request) Create page result from request 从请求创建分页结果static <T> PageResult<T> Create page result 创建分页结果pageInfo()Returns the value of thepageInforecord component.static <T> PageResult<T> Create single item result from list (takes first item) 从列表创建单项结果(取第一项)static <T> PageResult<T> single(T item) Create single item result 创建单项结果final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
PageResult
-
-
Method Details
-
of
Create page result 创建分页结果- Type Parameters:
T- the item type | 项类型- Parameters:
items- the items | 项列表pageInfo- the page info | 分页信息- Returns:
- the result | 结果
-
of
Create page result 创建分页结果- Type Parameters:
T- the item type | 项类型- Parameters:
items- the items | 项列表total- the total count | 总数page- the page number | 页码size- the page size | 页大小- Returns:
- the result | 结果
-
of
Create page result from request 从请求创建分页结果- Type Parameters:
T- the item type | 项类型- Parameters:
items- the items | 项列表total- the total count | 总数request- the page request | 分页请求- Returns:
- the result | 结果
-
empty
Create empty result 创建空结果- Type Parameters:
T- the item type | 项类型- Returns:
- the result | 结果
-
empty
Create empty result with page info 创建带分页信息的空结果- Type Parameters:
T- the item type | 项类型- Parameters:
page- the page number | 页码size- the page size | 页大小- Returns:
- the result | 结果
-
single
Create single item result 创建单项结果- Type Parameters:
T- the item type | 项类型- Parameters:
item- the single item | 单个项- Returns:
- the result with single item | 包含单项的结果
-
single
Create single item result from list (takes first item) 从列表创建单项结果(取第一项)- Type Parameters:
T- the item type | 项类型- Parameters:
list- the list | 列表- Returns:
- the result with single item | 包含单项的结果
-
getPage
public int getPage()Get page number 获取页码- Returns:
- the page number | 页码
-
getSize
public int getSize()Get page size 获取页大小- Returns:
- the page size | 页大小
-
getTotal
public long getTotal()Get total count 获取总数- Returns:
- the total count | 总数
-
getTotalPages
public int getTotalPages()Get total pages 获取总页数- Returns:
- the total pages | 总页数
-
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
-
getCount
public int getCount()Get item count 获取项数量- Returns:
- the item count | 项数量
-
map
Map items to another type 将项映射为另一种类型- Type Parameters:
R- the result type | 结果类型- Parameters:
mapper- the mapper function | 映射函数- Returns:
- the new page result | 新分页结果
-
mapList
Map entire list to another type 转换整个列表为另一种类型- Type Parameters:
R- the result type | 结果类型- Parameters:
mapper- the list mapper function | 列表映射函数- Returns:
- the new page result | 新分页结果
-
getFirst
-
getLast
-
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 withObjects::equals(Object,Object). -
items
-
pageInfo
-