/**
* 分页数据Bo转Vo
* @Author:杨群
* @Date: 2024/8/30 15:40
*/
public static <B, V> void convertTableDataInfo(TableDataInfo<B> source, @NotNull TableDataInfo<V> target, Class<V> targetClass) {
if (target==null) {
throw new BizException("数据转换发生异常!目标对象不能为空!");
}
if (source==null||source.getTotal() == 0 || CollectionUtils.isEmpty(source.getRows())) {
target.setTotal(0);
target.setRows(new ArrayList<>());
return;
}
BeanUtils.copyProperties(source,target);
target.setRows(source.getRows().stream().map(boRow -> {
V targetRow;
try {
targetRow = targetClass.getDeclaredConstructor().newInstance();
} catch (Exception e){
throw new BizException("数据转换发生异常!");
}
BeanUtils.copyProperties(boRow,targetRow);
return targetRow;
}).collect(Collectors.toList()));
}
若依分页数据Bo转Vo
最新推荐文章于 2024-10-12 22:35:37 发布