/**
* 根据指定的类型(targetClazz)实例化一个bean,并将source bean的属性赋值给实例化的bean
*
* @param source
* @param targetClazz
* @return
*/
public static <T> T beanUtils(Object source, Class<T> targetClazz) {
T target = null;
try {
target = targetClazz.newInstance();
} catch (Exception e) {
throw new RuntimeException("实例化" + targetClazz + "失败!");
}
BeanUtils.copyProperties(source, target);
return target;
}
最近用到的一个java方法泛型
Java Bean属性复制
最新推荐文章于 2024-07-10 22:13:59 发布
1万+

被折叠的 条评论
为什么被折叠?



