feature(cofiguration): 分页增加额外的参数

This commit is contained in:
2023-06-09 14:31:51 +08:00
parent a4160b2fb6
commit 4024c83c38

View File

@@ -1,7 +1,9 @@
package com.lanyuanxiaoyao.service.configuration.entity; package com.lanyuanxiaoyao.service.configuration.entity;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* 分页实体类 * 分页实体类
@@ -12,6 +14,7 @@ import java.util.List;
public class PageResponse<T> { public class PageResponse<T> {
private List<T> data = new ArrayList<>(0); private List<T> data = new ArrayList<>(0);
private Long total = 0L; private Long total = 0L;
private Map<String, Object> metadata = new HashMap<>();
public PageResponse() { public PageResponse() {
} }
@@ -22,10 +25,15 @@ public class PageResponse<T> {
} }
public PageResponse(List<T> data, Long total) { public PageResponse(List<T> data, Long total) {
this.data = data; this(data);
this.total = total; this.total = total;
} }
public PageResponse(List<T> data, Long total, Map<String, Object> metadata) {
this(data, total);
this.metadata = metadata;
}
public List<T> getData() { public List<T> getData() {
return data; return data;
} }
@@ -42,11 +50,25 @@ public class PageResponse<T> {
this.total = total; this.total = total;
} }
public Map<String, Object> getMetadata() {
return metadata;
}
public void setMetadata(Map<String, Object> metadata) {
this.metadata = metadata;
}
public PageResponse<T> withMetadata(String key, Object value) {
this.metadata.put(key, value);
return this;
}
@Override @Override
public String toString() { public String toString() {
return "PageResponse{" + return "PageResponse{" +
"data=" + data + "data=" + data +
", total=" + total + ", total=" + total +
", metadata=" + metadata +
'}'; '}';
} }
} }