Java DO到DTO转换利用spring 的BeanUtils.copyPropertiesJava DO到DTO转换利用spring 的BeanUtils.copyProperties()
原创
©著作权归作者所有:来自51CTO博客作者wx60bc17759a517的原创作品,请联系作者获取转载授权,否则将追究法律责任
Java DO到DTO转换利用spring 的BeanUtils.copyProperties()
public static <T> List<T> copy(Object sourceList, Class<?> beanClass) throws Exception {
List<Object> sList = (List<Object>) sourceList;
List<Object> tList = new ArrayList<Object>();
for (Object t : sList) {
Object dto = beanClass.newInstance();
BeanUtils.copyProperties(t, dto);
tList.add(dto);
}
return (List<T>) tList;
}
List<DTO> dtoList = copy(doList,DTO.class);