public static <E, V> Page<V> convertEntityPageToVoPage(Page<E> entityPage, Class<V> voClass) {
List<E> entityList = entityPage.getRecords();
List<V> voList = entityList.stream()
.map(entity -> {
V vo = null;
try {
vo = voClass.getDeclaredConstructor().newInstance();
BeanUtil.copyProperties(entity, vo);
} catch (Exception e) {
e.printStackTrace();
}
return vo;
})
.collect(Collectors.toList());
Page<V> voPage = new Page<>(entityPage.getCurrent(), entityPage.getSize(), entityPage.getTotal());
voPage.setRecords(voList);
return voPage;
}
分页数据转换工具 ex:entity->vo
最新推荐文章于 2024-08-30 18:40:43 发布