package com.ruoyi.warehouseBusiness.excel;

import cn.hutool.core.bean.BeanUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.compress.utils.Lists;
import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.Map;

public class ListMapToBeanUtils {
    /**
     * List<Map<String, Object>>转List<T>
     */
    public static <T> List<T> castMapToBean(List<Map<String, Object>> list, Class<T> clazz) throws Exception {

        if (list == null || list.size()==0) {
            return null;
        }

        List<T> output = Lists.newArrayList();
        if (CollectionUtils.isNotEmpty(list)) {
            for (Map<String, Object> source : list) {
                T target = BeanUtils.instantiateClass(clazz);
                BeanUtil.copyProperties(source, target);
                output.add(target);
            }
        }
        return output;

    }

}
