feat: 增加page convert
This commit is contained in:
parent
f1925adc85
commit
d49b863f78
@ -17,6 +17,8 @@ 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 {
|
||||
|
||||
@ -88,6 +90,14 @@ public class PageConverter {
|
||||
return totalData;
|
||||
}
|
||||
|
||||
public static <T, R> Page<R> convert(Page<T> page, Function<? super T, ? extends R> mapper) {
|
||||
List<R> collect = page.getRecords().stream().map(mapper).collect(toList());
|
||||
|
||||
Page<R> result = new Page<>(page.getCurrent(), page.getSize(), page.getTotal());
|
||||
result.setRecords(collect);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将MybatisPlus的IPage转换为spring的Page, 用于返回
|
||||
*
|
||||
|
||||
Loading…
Reference in New Issue
Block a user