|
@@ -6,7 +6,6 @@ import java.util.Map;
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.Page;
|
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
import com.google.common.collect.Lists;
|
|
-
|
|
|
|
import lombok.NonNull;
|
|
import lombok.NonNull;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -23,8 +22,8 @@ public class PaginationHelper {
|
|
* @param page
|
|
* @param page
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public static PaginationResult create(Page<?> page) {
|
|
|
|
- return create(page.toList(), (int) page.getTotalElements());
|
|
|
|
|
|
+ public static <T> PaginationResult<T> create(Page<T> page) {
|
|
|
|
+ return create(page.getContent(), (int) page.getTotalElements());
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -33,8 +32,8 @@ public class PaginationHelper {
|
|
* @param page
|
|
* @param page
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public static PaginationResult create(Page<?> page, Map<String, Object> extData) {
|
|
|
|
- PaginationResult paginationResult = create(page.toList(), (int) page.getTotalElements());
|
|
|
|
|
|
+ public static <T> PaginationResult<T> create(Page<T> page, Map<String, Object> extData) {
|
|
|
|
+ PaginationResult<T> paginationResult = create(page.getContent(), (int) page.getTotalElements());
|
|
paginationResult.extData = extData;
|
|
paginationResult.extData = extData;
|
|
return paginationResult;
|
|
return paginationResult;
|
|
}
|
|
}
|
|
@@ -43,8 +42,8 @@ public class PaginationHelper {
|
|
* 构造空的返回
|
|
* 构造空的返回
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public static PaginationResult createEmpty() {
|
|
|
|
- return PaginationResult.builder().code(1).msg("No data").data(Lists.newArrayList()).count(0).build();
|
|
|
|
|
|
+ public static <T> PaginationResult<T> createEmpty() {
|
|
|
|
+ return PaginationResult.<T>builder().code(1).msg("No data").data(Lists.newArrayList()).count(0).build();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -54,12 +53,12 @@ public class PaginationHelper {
|
|
* @param total
|
|
* @param total
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public static PaginationResult create(@NonNull List<?> data, Integer total) {
|
|
|
|
- List<?> list = Lists.newArrayList(data);
|
|
|
|
|
|
+ public static <T> PaginationResult<T> create(@NonNull List<T> data, Integer total) {
|
|
|
|
+ List<T> list = Lists.newArrayList(data);
|
|
if (list.isEmpty()) {
|
|
if (list.isEmpty()) {
|
|
- return PaginationResult.builder().code(1).msg("No data").data(Lists.newArrayList()).count(0).build();
|
|
|
|
|
|
+ return PaginationResult.<T>builder().code(1).msg("No data").data(Lists.newArrayList()).count(0).build();
|
|
} else {
|
|
} else {
|
|
- return PaginationResult.builder().code(0).data(list).count(total).build();
|
|
|
|
|
|
+ return PaginationResult.<T>builder().code(0).data(list).count(total).build();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -70,12 +69,12 @@ public class PaginationHelper {
|
|
* @param total
|
|
* @param total
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public static PaginationResult create(@NonNull List<?> data, Integer total, Integer page) {
|
|
|
|
- List<?> list = Lists.newArrayList(data);
|
|
|
|
|
|
+ public static <T> PaginationResult<T> create(@NonNull List<T> data, Integer total, Integer page) {
|
|
|
|
+ List<T> list = Lists.newArrayList(data);
|
|
if (list.isEmpty()) {
|
|
if (list.isEmpty()) {
|
|
- return PaginationResult.builder().code(1).msg("No data").data(Lists.newArrayList()).count(0).page(1).build();
|
|
|
|
|
|
+ return PaginationResult.<T>builder().code(1).msg("No data").data(Lists.newArrayList()).count(0).page(1).build();
|
|
} else {
|
|
} else {
|
|
- return PaginationResult.builder().code(0).data(list).count(total).page(page).build();
|
|
|
|
|
|
+ return PaginationResult.<T>builder().code(0).data(list).count(total).page(page).build();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|