package com.mshuoke.framework.starter.common.util;
import org.dozer.DozerBeanMapper;
import java.util.ArrayList;
import java.util.List;
public class BeanConvertUtil {
/**
* 将srcList中的元素复制到元素类型为descClass的List集合中
*
* @param srcList
* @param descClass
* @return
*/
public static <T> List<T> copyList(List srcList, Class<T> descClass) {
List<T> descList = new ArrayList<T>();
if (srcList != null) {
for (Object obj : srcList) {
T t = copyProperties(obj, descClass);
descList.add(t);
}
}
return descList;
}
/**
* 将src对象中的属性值复制到新建的desc对象的同名属性中
*
* @param src
* @param descClass
* @return
*/
public static <T> T copyProperties(Object src, Class<T> descClass) {
DozerBeanMapper dozer = new DozerBeanMapper();
return (T) dozer.map(src, descClass);
}
}