-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added LayuiPageVO and update versio to 3.7.4
- Loading branch information
1 parent
42cc82a
commit cb9b00a
Showing
2 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/main/java/cn/woodwhales/common/model/vo/LayuiPageVO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package cn.woodwhales.common.model.vo; | ||
|
||
import cn.woodwhales.common.model.enums.RespCodeEnum; | ||
import com.baomidou.mybatisplus.core.metadata.IPage; | ||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.function.Function; | ||
|
||
import static java.util.Collections.emptyList; | ||
import static java.util.stream.Collectors.toList; | ||
|
||
/** | ||
* layui 分页响应对象 | ||
* @author woodwhales on 2022-06-10 14:15 | ||
*/ | ||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class LayuiPageVO<T> { | ||
|
||
/** | ||
* 响应成功状态码 | ||
*/ | ||
private Integer code; | ||
|
||
/** | ||
* 响应描述 | ||
*/ | ||
private String msg; | ||
|
||
/** | ||
* 总记录数 | ||
*/ | ||
private Long count; | ||
|
||
/** | ||
* 当前分页记录集合 | ||
*/ | ||
private List<T> data; | ||
|
||
public static <S, T> LayuiPageVO<T> build(IPage<S> page, | ||
Function<? super S, ? extends T> mapper, | ||
Comparator<T> comparator) { | ||
if (CollectionUtils.isEmpty(page.getRecords())) { | ||
return build(RespCodeEnum.SUCCESS, page.getTotal(), emptyList()); | ||
} | ||
|
||
return build(RespCodeEnum.SUCCESS, page.getTotal(), page.getRecords() | ||
.stream() | ||
.map(mapper) | ||
.sorted(comparator) | ||
.collect(toList())); | ||
} | ||
|
||
public static <T> LayuiPageVO<T> build(RespCodeEnum respCodeEnum, long total, List<T> data) { | ||
return new LayuiPageVO<>(respCodeEnum.getCode(), respCodeEnum.getMessage(), total, data); | ||
} | ||
|
||
} |