java - BeanUtils.copyproperties 日期属性复制问题?

标签 java apache-commons-beanutils

我正在使用 commons-beanutils 1.8.3 和 Date 属性作为 java.util.Date。

当我尝试将源复制到目标时,它无法复制日期属性。

以下是我之前的问题,但是没有人给我正确的答案。

例如,我在源 bean 中的日期值为 Wed May 15 15:46:04 IST 2013,但 BeanUtils 无法将其复制到目标...

BeanUtills Date conversion Issue

最佳答案

这是我解决问题的方法。

    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/

相关文章:

java - BeanUtils.copyProperties 产生 java.lang.VerifyError :

java - Spring Batch + Spring API REST

java - 如何使用 if 语句将 URL 解析为某个 IP 地址?

java - 当从另一个类调用方法时 - 返回一个难以理解的值 JAVA

java - 对数组元素的奇数索引求和

java - Spring Bean 复制属性忽略子对象的空值

java - BeanUtils - 'describe' 方法返回不正确的数组值

java - beanutil 可以使用其 native 类型获取一个字段的属性吗

java - 反射将非空属性从一个对象复制到另一个 BeanUtils

java - 保持类独立性或避免类型检查