package com.ylcm.sys.common;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeanUtils;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class MyBeanUtils {

    /**
     * 复制list
     * @param list 源list
     * @param targetClass  目标对象class
     * @return list<T> ArrayList
     */
    public static <T> List<T> copyList(List<?> list,  Class<T> targetClass){
        if(list==null){
            return null;
        }
        List<T> result = new  ArrayList<>();
        if(list.size()==0){
            return  result;
        }
        for (Object o : list) {
            try {
                T t = targetClass.newInstance();
                BeanUtils.copyProperties(o,t);
                result.add(t);
            } catch (Exception e) {
               log.error(e.getMessage(),e);
            }
        }
        return result;
    }

}
