feat:增加page的convert

This commit is contained in:
lilong 2024-05-06 11:00:35 +08:00
parent 90bbb991b9
commit db28d2fbc5

View File

@ -12,7 +12,8 @@ import org.apache.commons.lang3.BooleanUtils;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;
import static java.util.stream.Collectors.toList;
@UtilityClass
public class PageConverter {
@ -48,7 +49,7 @@ public class PageConverter {
public static <T> PageResp toResp(IPage<T> page) {
List<String> sorts = page.orders().stream()
.map(e -> e.getColumn().concat(IPageReq.SORT_DELIMITER).concat(e.isAsc() ? IPageReq.SORT_ASC : IPageReq.SORT_DESC))
.collect(Collectors.toList());
.collect(toList());
PageResp result = PageResp.builder()
.total(page.getTotal())
.current(page.getCurrent())
@ -102,4 +103,16 @@ public class PageConverter {
}
return totalData;
}
public static <T, R> PageResp<R> convert(IPage<T> page, Function<? super T, ? extends R> mapper) {
List<R> collect = page.getRecords().stream().map(mapper).collect(toList());
PageResp result = PageResp.builder()
.total(page.getTotal())
.current(page.getCurrent())
.size(page.getSize())
.build();
result.setData(collect);
return result;
}
}