工具類-複製物件BeanUtil
阿新 • • 發佈:2018-11-09
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public final class BeanUtil {
private static Log log = LogFactory.getLog(BeanUtils.class);
/**
* 建構函式
*/
private BeanUtil() { }
/**
* vo do之間的對考,要求屬性名相同,型別匹配
* @param target 目標
* @param resource 源
*/
public static void copyProperties(Object target, Object resource) {
try {
PropertyUtils.copyProperties(target, resource);
} catch (Exception e) {
String msg ="物件引數複製異常!" ;
log.error(msg, e);
throw new RuntimeException(msg);
}
}
}