|
@@ -6,6 +6,7 @@ import java.util.List;
|
|
import java.util.function.Function;
|
|
import java.util.function.Function;
|
|
|
|
|
|
import com.chelvc.framework.common.util.ObjectUtils;
|
|
import com.chelvc.framework.common.util.ObjectUtils;
|
|
|
|
+import com.fasterxml.jackson.annotation.JsonIgnore;
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.Builder;
|
|
import lombok.Builder;
|
|
import lombok.EqualsAndHashCode;
|
|
import lombok.EqualsAndHashCode;
|
|
@@ -62,6 +63,16 @@ public class Pagination<T> implements Serializable {
|
|
return (Pagination<T>) EMPTY_PAGINATION;
|
|
return (Pagination<T>) EMPTY_PAGINATION;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 判断分页记录是否为空
|
|
|
|
+ *
|
|
|
|
+ * @return true/false
|
|
|
|
+ */
|
|
|
|
+ @JsonIgnore
|
|
|
|
+ public boolean isEmpty() {
|
|
|
|
+ return ObjectUtils.isEmpty(this.records);
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 数据转换
|
|
* 数据转换
|
|
*
|
|
*
|
|
@@ -70,7 +81,7 @@ public class Pagination<T> implements Serializable {
|
|
* @return 数据列表分页实例
|
|
* @return 数据列表分页实例
|
|
*/
|
|
*/
|
|
public <M> Pagination<M> convert(@NonNull Class<M> type) {
|
|
public <M> Pagination<M> convert(@NonNull Class<M> type) {
|
|
- return Pagination.<M>builder().total(this.total).pages(this.pages)
|
|
|
|
|
|
+ return this.isEmpty() ? empty() : Pagination.<M>builder().total(this.total).pages(this.pages)
|
|
.records(ObjectUtils.copying(this.records, type)).build();
|
|
.records(ObjectUtils.copying(this.records, type)).build();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -82,6 +93,7 @@ public class Pagination<T> implements Serializable {
|
|
* @return 数据列表分页实例
|
|
* @return 数据列表分页实例
|
|
*/
|
|
*/
|
|
public <M> Pagination<M> convert(@NonNull Function<List<T>, List<M>> adapter) {
|
|
public <M> Pagination<M> convert(@NonNull Function<List<T>, List<M>> adapter) {
|
|
- return Pagination.<M>builder().total(this.total).pages(this.pages).records(adapter.apply(this.records)).build();
|
|
|
|
|
|
+ return this.isEmpty() ? empty() : Pagination.<M>builder().total(this.total).pages(this.pages)
|
|
|
|
+ .records(adapter.apply(this.records)).build();
|
|
}
|
|
}
|
|
}
|
|
}
|