// K原list类型,T想要变成的类型
@Component
public class BeanUtils<K, T> {
public <T> List<T> copyList(List<K> k, Class<T> t){
List<T> ts = new ArrayList<>();
for(K item : k) {
T t1 = null;
try {
t1 = t.newInstance();
} catch (Exception e) {
e.printStackTrace();
}
org.springframework.beans.BeanUtils.copyProperties(item, t1);
ts.add(t1);
}
return ts;
}
}
List整体复制成另一个类型的List集合
于 2024-01-17 15:36:00 首次发布