1. 程式人生 > >把一個物件的屬性值拷貝到另一個物件上去

把一個物件的屬性值拷貝到另一個物件上去

public static void copyProperties(Object dest,Object src){
        try{
            ConvertUtils.register(new DateConverter(null),java.util.Date.class);
            ConvertUtils.register(new SqlTimestampConverter(null), Timestamp.class);
            BeanUtils.copyProperties(dest,src);
        }catch (Exception e){
            logger.error("copyProperties {}",e);
        }

    }

org.apache.commons.beanutils.ConvertUtils

org.apache.commons.beanutils.BeanUtils

    public static void copyProperties(Object dest, Object orig)
        throws IllegalAccessException, InvocationTargetException {
        
        BeanUtilsBean.getInstance().copyProperties(dest, orig);
    }