gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 07:08:41 29 4
gpt4 key购买 nike

我正在使用 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/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com