本文共 852 字,大约阅读时间需要 2 分钟。
public class CopyBeanUtil { /** * 复制对象 * * @param source 源 要复制的对象 * @param target 目标 复制到此对象 * @param* @return */ public static T copy(Object source, Class target) { try { T newInstance = target.newInstance(); BeanUtils.copyProperties(source, newInstance); return newInstance; } catch (Exception e) { throw new RuntimeException(e); } } /** * 复制list * * @param source * @param target * @param * @param * @return */ public static List copyList(List source, Class target) { if (null == source || source.isEmpty()) { return Collections.emptyList(); } return source.stream().map(e -> copy(e, target)).collect(Collectors.toList()); }}
转载地址:http://uwamb.baihongyu.com/