其他分享
首页 > 其他分享> > 6.12---前提两个对象的成员必须一致,才能将有数据的对象将数据传给反射获取的对象conver(有数据对象,目标对象)

6.12---前提两个对象的成员必须一致,才能将有数据的对象将数据传给反射获取的对象conver(有数据对象,目标对象)

作者:互联网

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.yx.AIHome.AIHome_common.base.utils;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.springframework.beans.BeanUtils;

public class ConvertUtils {
public ConvertUtils() {
}

public static <T> T convert(Object src, Class<T> destClass) {
try {
T result = destClass.newInstance();
BeanUtils.copyProperties(src, result);
return result;
} catch (Exception var3) {
throw new RuntimeException(var3.getMessage(), var3);
}
}

public static <T> List<T> convert(List<?> srcList, Class<T> destClass) {
List<T> resultList = new ArrayList();
Iterator var3 = srcList.iterator();

while(var3.hasNext()) {
Object src = var3.next();
T dest = convert(src, destClass);
resultList.add(dest);
}

return resultList;
}
}

标签:src,var3,对象,6.12,List,destClass,import,数据,public
来源: https://www.cnblogs.com/wym591273/p/11010591.html