import org.springframework.beans.BeanUtils;
/**
* List<DO>转List<VO>
*/
public static <T> List<T> copyList(List<Object> doList, Class<T> voClass) {
List<T> voList = new ArrayList<>();
try {
T voObj = null;
for (Object doObj : doList) {
voObj = voClass.newInstance();
BeanUtils.copyProperties(doObj, voObj);
voList.add(voObj);
}
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return voList;
}
/**
* DO转VO
*/
public static <T> T copyObj(Object doObject, Class<T> voClass) {
T voObj = null;
try {
voObj = voClass.newInstance();
BeanUtils.copyProperties(doClass, voObj);
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return voObj;
}
08-09
1029
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
09-21
1153
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)