bug宝典JAVA篇 BeanUtils.copyProperties 日期问题

来源:互联网 发布:2016年网络流行词汇 编辑:程序博客网 时间:2024/06/05 16:05

执行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就是日期类型,转字符串自然就报错了。
1
稍作调整如下:
2

0 0
原创粉丝点击