Class ScrollResponse<T>
java.lang.Object
cn.dinodev.spring.commons.response.Response<Collection<? extends T>>
cn.dinodev.spring.commons.response.ScrollResponse<T>
- Type Parameters:
T- 响应数据元素类型
REST API滑动窗口响应类,用于分页滚动加载
- Since:
- 2022-07-11
- Author:
- Cody Lu
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedScrollResponse(int code, String msg) 构造函数,用于创建失败的响应protectedScrollResponse(Collection<? extends T> list, String nextCursor, boolean hasMore) 构造函数,用于创建成功的响应 -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> ScrollResponse<T> 创建一个失败的分页响应static <T> ScrollResponse<T> 创建一个失败的分页响应set(Collection<? extends T> list, String nextCursor, boolean hasMore) 设置滚动响应的数据Response<Collection<? extends T>> setData(Collection<? extends T> list) static <T> ScrollResponse<T> success(Collection<? extends T> list, String nextCursor, boolean hasMore) 创建一个成功的滚动响应static <T,S> ScrollResponse <T> success(Collection<S> list, Function<Collection<S>, Collection<? extends T>> converter, String nextCursor, boolean hasMore) 创建一个成功的滚动响应,并对数据进行转换static <T> ScrollResponse<T> successWithMore(Collection<? extends T> list, String nextCursor) 创建一个表示有更多数据的成功滚动响应static <T> ScrollResponse<T> successWithNoMore(Collection<? extends T> list) 创建一个表示没有更多数据的成功滚动响应
-
Constructor Details
-
ScrollResponse
构造函数,用于创建失败的响应- Parameters:
code- 状态码msg- 消息
-
ScrollResponse
protected ScrollResponse(Collection<? extends T> list, @Nullable String nextCursor, boolean hasMore) 构造函数,用于创建成功的响应- Parameters:
list- 数据列表nextCursor- 下一个游标hasMore- 是否有更多数据
-
-
Method Details
-
set
public ScrollResponse<T> set(Collection<? extends T> list, @Nullable String nextCursor, boolean hasMore) 设置滚动响应的数据- Parameters:
list- 数据列表nextCursor- 下一个游标hasMore- 是否有更多数据- Returns:
- 当前
ScrollResponse实例
-
setData
-
success
public static <T> ScrollResponse<T> success(@Nonnull Collection<? extends T> list, @Nullable String nextCursor, boolean hasMore) 创建一个成功的滚动响应- Type Parameters:
T- 数据类型- Parameters:
list- 数据列表nextCursor- 下一个滚动IDhasMore- 是否有更多数据- Returns:
- 成功的滚动响应
-
success
public static <T,S> ScrollResponse<T> success(@Nonnull Collection<S> list, @Nonnull Function<Collection<S>, Collection<? extends T>> converter, @Nullable String nextCursor, boolean hasMore) 创建一个成功的滚动响应,并对数据进行转换- Type Parameters:
T- 目标数据类型S- 原始数据类型- Parameters:
list- 原始数据列表converter- 数据转换函数nextCursor- 下一个游标hasMore- 是否有更多数据- Returns:
- 转换后的成功滚动响应
-
successWithMore
public static <T> ScrollResponse<T> successWithMore(@Nonnull Collection<? extends T> list, @Nonnull String nextCursor) 创建一个表示有更多数据的成功滚动响应- Type Parameters:
T- 数据类型- Parameters:
list- 数据列表nextCursor- 下一个游标- Returns:
- 成功的滚动响应
-
successWithNoMore
创建一个表示没有更多数据的成功滚动响应- Type Parameters:
T- 数据类型- Parameters:
list- 数据列表- Returns:
- 成功的滚动响应
-
failPage
创建一个失败的分页响应- Type Parameters:
T- 数据类型- Parameters:
msg- 失败消息- Returns:
- 失败的滚动响应
-
failPage
创建一个失败的分页响应- Type Parameters:
T- 数据类型- Parameters:
status- 状态- Returns:
- 失败的滚动响应
-