美文网首页
属性拷贝

属性拷贝

作者: bigfish1129 | 来源:发表于2018-06-01 15:55 被阅读0次

    public class DataTransformUtil<T1, T2> {
    public static <T1, T2> void transform(T1 source, T2 target) {
    try {
    PropertyUtils.copyProperties(target, source);
    } catch (Exception e) {
    logger.error(e);
    }
    }
    public static <T1, T2> List<T2> transformList(List<T1> sources, Class<T2> classObj) {
    List<T2> targets = new ArrayList<>();
    try {
    for (T1 source : sources) {
    T2 target = classObj.newInstance();
    transform(source, target);
    targets.add(target);
    }
    } catch (Exception e) {
    logger.error(e);
    }
    return targets;
    }

    }

    相关文章

      网友评论

          本文标题:属性拷贝

          本文链接:https://www.haomeiwen.com/subject/pflksftx.html