import com.ssht.common.utils.bean.BeanUtils;
import java.util.ArrayList;
import java.util.List;
public class ConvertUtils {
public static <T, E> E convert(T source, Class<E> targetClass) {
E target = null;
try {
target = targetClass.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
e.printStackTrace();
return null;
}
BeanUtils.copyProperties(source, target);
return target;
}
public static <T, E> List<E> convertList(List<T> sourceList, Class<E> targetClass) {
List<E> targetList = new ArrayList<>();
for (T source : sourceList) {
E target = convert(source, targetClass);
targetList.add(target);
}
return targetList;
}
}
两个List对象集合同字段互转工具
最新推荐文章于 2024-05-06 00:11:14 发布