//接口,集合之間的數(shù)據(jù)復(fù)制
public interface ColaBeanUtilsCallBack {
void callBack(S t,T s);
}
//實(shí)現(xiàn)類
/*
* 集合賦值到集合工具* 老的對(duì)象? 新的集合對(duì)象* */
public class ColaBeanUtils extends BeanUtils {
public static ListcopyListProperties(Listsources, Suppliertarget) {
return copyListProperties(sources, target, null);
? ? }
/**
? ? * 使用場(chǎng)景:Entity、Bo季希、Vo層數(shù)據(jù)的復(fù)制褪那,因?yàn)锽eanUtils.copyProperties只能給目標(biāo)對(duì)象的屬性賦值,卻不能在List集合下循環(huán)賦值式塌,因此添加該方法
? ? * 如:List<AdminEntity> 賦值到 List<AdminVo> 博敬,List<AdminVo>中的 AdminVo 屬性都會(huì)被賦予到值
? ? * S: 數(shù)據(jù)源類 ,T: 目標(biāo)類::new(eg: AdminVo::new)
*/
? ? public static ListcopyListProperties(Listsources, Suppliertarget, ColaBeanUtilsCallBackcallBack) {
Listlist =new ArrayList<>(sources.size());
? ? ? ? for (S source :sources) {
T t =target.get();
? ? ? ? ? ? copyProperties(source, t);
? ? ? ? ? ? if (callBack !=null) {
// 回調(diào)
? ? ? ? ? ? ? ? callBack.callBack(source,t);
? ? ? ? ? ? }
list.add(t);
? ? ? ? }
return list;
? ? }
}