学习记录
package cn.xxx.sx.zm.utils;
import cn.hutool.core.bean.BeanUtil;
import java.util.List;
import java.util.stream.Collectors;
public class ConvertUtil {
public final static <S,T> T convert(S source,Class<T> clz){
T target = null;
try {
target = clz.newInstance();
BeanUtil.copyProperties(source,target);
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return target;
}
public static <S,T> List<T> convertList(List<S> sourceList, Class<T> clz){
return sourceList.stream().map(e->{
return convert(e,clz);
}).collect(Collectors.toList());
}
}
public static void main(String[] args) {
MaterialsInventoryBill materialsInventoryBill= ConvertUtil.convert(materialsInventoryBillVO,MaterialsInventoryBill.class);
}