bug宝典JAVA篇 BeanUtils.copyProperties 日期问题
2017-01-01 08:53
375 查看
执行
debug发现,红色方框内容有问题,本来arg1就是日期类型,转字符串自然就报错了。
稍作调整如下:
BeanUtils.copyProperties(dest, orig);的时候出现下面的错误,我的代码如下,主要目的是复制对象,但是又不想一个个set,下面的
BeanUtilsExtends是照着copyproperties 谁赋值给谁抄的,实际运用却出现下面的问题
@Transactional(readOnly = false) private boolean createNewRecord(FontalMaintainLog record, Date nextOptDate){ FontalMaintainLog newRecord = new FontalMaintainLog(); BeanUtilsExtends.copyProperties(newRecord, record); newRecord.setId(StringUtil.getUuidString()); newRecord.setOptDate(nextOptDate); return insertSelective(newRecord); }
Caused by: java.lang.ClassCastException: java.util.Date cannot be cast to java.lang.String at com.dzmsoft.framework.base.util.DateConvert.convert(DateConvert.java:9) ~[classes/:na] at org.apache.commons.beanutils.BeanUtilsBean.convert(BeanUtilsBean.java:1078) ~[commons-beanutils-1.8.3.jar:1.8.3] at org.apache.commons.beanutils.BeanUtilsBean.copyProperty(BeanUtilsBean.java:437) ~[commons-beanutils-1.8.3.jar:1.8.3] at org.apache.commons.beanutils.BeanUtilsBean.copyProperties(BeanUtilsBean.java:286) ~[commons-beanutils-1.8.3.jar:1.8.3] at org.apache.commons.beanutils.BeanUtils.copyProperties(BeanUtils.java:137) ~[commons-beanutils-1.8.3.jar:1.8.3] at com.dzmsoft.framework.base.util.BeanUtilsExtends.copyProperties(BeanUtilsExtends.java:16) ~[classes/:na] at com.dzmsoft.fontal.base.service.impl.FontalMaintainLogServiceImpl.createNewRecord(FontalMaintainLogServiceImpl.java:253) ~[classes/:na] at com.dzmsoft.fontal.base.service.impl.FontalMaintainLogServiceImpl.genMaintainLogByNoFinish(FontalMaintainLogServiceImpl.java:117) ~[classes/:na] at com.dzmsoft.fontal.base.service.impl.FontalMaintainLogServiceImpl$$FastClassBySpringCGLIB$$735c3ac8.invoke(<generated>) ~[classes/:na] at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) ~[spring-core-4.2.5.RELEASE.jar:4.2.5.RELEASE] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:720) ~[spring-aop-4.2.5.RELEASE.jar:4.2.5.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.2.5.RELEASE.jar:4.2.5.RELEASE] at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) ~[spring-tx-4.2.5.RELEASE.jar:4.2.5.RELEASE] at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281) ~[spring-tx-4.2.5.RELEASE.jar:4.2.5.RELEASE] at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) ~[spring-tx-4.2.5.RELEASE.jar:4.2.5.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.2.5.RELEASE.jar:4.2.5.RELEASE] at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655) ~[spring-aop-4.2.5.RELEASE.jar:4.2.5.RELEASE] at com.dzmsoft.fontal.base.service.impl.FontalMaintainLogServiceImpl$$EnhancerBySpringCGLIB$$be923a94.genMaintainLogByNoFinish(<generated>) ~[classes/:na] at com.dzmsoft.fontal.base.service.impl.FontalEndProcessServiceImpl.genNextMaintain(FontalEndProcessServiceImpl.java:164) ~[classes/:na] at com.dzmsoft.fontal.base.service.impl.FontalEndProcessServiceImpl.nextOptDate(FontalEndProcessServiceImpl.java:155) ~[classes/:na] at com.dzmsoft.fontal.base.service.impl.FontalEndProcessServiceImpl.checkMaintainlog(FontalEndProcessServiceImpl.java:142) ~[classes/:na] at com.dzmsoft.fontal.base.service.impl.FontalEndProcessServiceImpl.deal(FontalEndProcessServiceImpl.java:81) ~[classes/:na]
debug发现,红色方框内容有问题,本来arg1就是日期类型,转字符串自然就报错了。
稍作调整如下:
相关文章推荐
- BeanUtils.copyProperties方法遇到null值问题
- 有关apache包里面的BeanUtils.copyProperties 字段类型为Integer或者Double时,自动赋值为默认值的问题随笔
- No value specified for 'Date' BeanUtils.copyProperties 日期为空 转型错误
- BeanUtils.copyProperties属性拷贝日期为空异常
- org.apache.commons.beanutils.copyProperties中复制不成功但是不报错问题
- BeanUtils.copyProperties方法遇到null值问题
- BeanUtils.copyProperties 复制对象异常问题
- BeanUtils.copyProperties出现了问题的原因
- org.springframework.beans.BeanUtils.copyProperties方法的泛型问题。
- BeanUtils.copyProperties 在copy Integer类型问题
- BeanUtils.copyProperties时日期的拷贝
- BeanUtils.copyProperties方法遇到null值问题
- 关于BeanUtils.copyProperties的使用
- BeanUtils.copyProperties、set、BeanCopier还有spring中的BeanUtils.copyProperties之间的区别
- BeanUtils.copyProperties与PropertyUtils.copyProperties用法及区别
- PropertyBeanUtils.copyProperties(dest, orig)
- BeanUtils.copyProperties与PropertyUtils.copyProperties用法及区别
- BeanUtils.copyProperties()的用法
- Apache Commons BeanUtils包学习(1)-BeanUtils.copyProperties
- commons-beanutils.jar包中BeanUtils.copyProperties方法对数值型值的注意