我正在使用 commons-beanutils 1.8.3 和 Date 属性作为 java.util.Date。
当我尝试将源复制到目标时,它无法复制日期属性。
以下是我之前的问题,但是没有人给我正确的答案。
例如,我在源 bean 中的日期值为 Wed May 15 15:46:04 IST 2013,但 BeanUtils 无法将其复制到目标...
最佳答案
这是我解决问题的方法。
public static void copyProperties(Object src, Object dest) throws IllegalAccessException,
InvocationTargetException, NoSuchMethodException {
java.util.Date defaultValue = null;
Converter converter = new DateConverter(defaultValue);
BeanUtilsBean beanUtilsBean = BeanUtilsBean.getInstance();
beanUtilsBean.getConvertUtils().register(converter, java.util.Date.class);
BeanUtils.copyProperties(dest, src);
}
关于java - BeanUtils.copyproperties 日期属性复制问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16579518/