Skip to content

Commit

Permalink
added LayuiPageVO and update versio to 3.7.4
Browse files Browse the repository at this point in the history
  • Loading branch information
woodwhales committed Jun 10, 2022
1 parent 42cc82a commit cb9b00a
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>cn.woodwhales.common</groupId>
<artifactId>woodwhales-common</artifactId>
<version>3.7.3</version>
<version>3.7.4</version>
<name>woodwhales-common</name>

<!-- 项目描述 -->
Expand Down
64 changes: 64 additions & 0 deletions src/main/java/cn/woodwhales/common/model/vo/LayuiPageVO.java
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);
}

}

0 comments on commit cb9b00a

Please sign in to comment.