集合对象转换
import org.springframework.beans.BeanUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;
public class BeanCopyUtil extends BeanUtils {
public static <S, T> List<T> copyListProperties(List<S> sources, Supplier<T> target) {
return copyListProperties(sources, target, null);
}
public static <S, T> List<T> copyListProperties(List<S> sources, Supplier<T> target, BeanCopyUtilCallBack<S, T> callBack) {
List<T> list = new ArrayList<>(sources.size());
for (S source : sources) {
T t = target.get();
copyProperties(source, t);
list.add(t);
if (callBack != null) {
callBack.callBack(source, t);
}
}
return list;
}
public static <S, T> T copyProperties(S source, Supplier<T> target, BeanCopyUtilCallBack<S, T> callBack) {
if (null == source){
return null;
}
T t = target.get();
copyProperties(source, t);
if (callBack != null) {
callBack.callBack(source, t);
}
return t;
}
}
@FunctionalInterface
public interface BeanCopyUtilCallBack<S, T> {
void callBack(S t, T s);
}