Field error in object ‘XXX‘ on field XXXXXXX‘

在图片多段提交时:
下面两张图片是网页多段提交到控制器,变量要保持同名:
Field error in object ‘XXX‘ on field XXXXXXX‘
Field error in object ‘XXX‘ on field XXXXXXX‘
但是与springmvc的自动映射相冲突,spring将优先将cp_pic映射至Cp类的cp_pic字段,而不是“MultipartFile cp_Pic”
Field error in object ‘XXX‘ on field XXXXXXX‘
处理方式:将多段提交对应的两个变量名更改为不同于类的实例变量名即可。

org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object 'cp' on field 'cp_pic': rejected value [org.springframework.web.multipart.commons.CommonsMultipartFile@5c4c608b]; codes [typeMismatch.cp.cp_pic,typeMismatch.cp_pic,typeMismatch.[B,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [cp.cp_pic,cp_pic]; arguments []; default message [cp_pic]]; default message [Failed to convert property value of type 'org.springframework.web.multipart.commons.CommonsMultipartFile' to required type 'byte[]' for property 'cp_pic'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type 'org.springframework.web.multipart.commons.CommonsMultipartFile' to required type 'byte' for property 'cp_pic[0]': PropertyEditor [org.springframework.beans.propertyeditors.CustomNumberEditor] returned inappropriate value of type 'org.springframework.web.multipart.commons.CommonsMultipartFile']
	at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.resolveArgument(ModelAttributeMethodProcessor.java:157)
	at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:124)
	at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:161)
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:131)
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:877)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:783)
	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:974)
	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:877)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:652)
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:851)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:690)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.base/java.lang.Thread.run(Thread.java:835)
2020-11-26 22:01:19,509 DEBUG (org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver:136) - Resolving exception from handler [public java.lang.String edu.mju.cpwork.controller.CpController.createCp(edu.mju.cpwork.domain.Cp,org.springframework.web.multipart.MultipartFile) throws java.lang.Exception]: org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object 'cp' on field 'cp_pic': rejected value [org.springframework.web.multipart.commons.CommonsMultipartFile@5c4c608b]; codes [typeMismatch.cp.cp_pic,typeMismatch.cp_pic,typeMismatch.[B,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [cp.cp_pic,cp_pic]; arguments []; default message [cp_pic]]; default message [Failed to convert property value of type 'org.springframework.web.multipart.commons.CommonsMultipartFile' to required type 'byte[]' for property 'cp_pic'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type 'org.springframework.web.multipart.commons.CommonsMultipartFile' to required type 'byte' for property 'cp_pic[0]': PropertyEditor [org.springframework.beans.propertyeditors.CustomNumberEditor] returned inappropriate value of type 'org.springframework.web.multipart.commons.CommonsMultipartFile']
2020-11-26 22:01:19,512 DEBUG (org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver:136) - Resolving exception from handler [public java.lang.String edu.mju.cpwork.controller.CpController.createCp(edu.mju.cpwork.domain.Cp,org.springframework.web.multipart.MultipartFile) throws java.lang.Exception]: org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object 'cp' on field 'cp_pic': rejected value [org.springframework.web.multipart.commons.CommonsMultipartFile@5c4c608b]; codes [typeMismatch.cp.cp_pic,typeMismatch.cp_pic,typeMismatch.[B,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [cp.cp_pic,cp_pic]; arguments []; default message [cp_pic]]; default message [Failed to convert property value of type 'org.springframework.web.multipart.commons.CommonsMultipartFile' to required type 'byte[]' for property 'cp_pic'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type 'org.springframework.web.multipart.commons.CommonsMultipartFile' to required type 'byte' for property 'cp_pic[0]': PropertyEditor [org.springframework.beans.propertyeditors.CustomNumberEditor] returned inappropriate value of type 'org.springframework.web.multipart.commons.CommonsMultipartFile']
2020-11-26 22:01:19,512 DEBUG (org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver:136) - Resolving exception from handler [public java.lang.String edu.mju.cpwork.controller.CpController.createCp(edu.mju.cpwork.domain.Cp,org.springframework.web.multipart.MultipartFile) throws java.lang.Exception]: org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object 'cp' on field 'cp_pic': rejected value [org.springframework.web.multipart.commons.CommonsMultipartFile@5c4c608b]; codes [typeMismatch.cp.cp_pic,typeMismatch.cp_pic,typeMismatch.[B,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [cp.cp_pic,cp_pic]; arguments []; default message [cp_pic]]; default message [Failed to convert property value of type 'org.springframework.web.multipart.commons.CommonsMultipartFile' to required type 'byte[]' for property 'cp_pic'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type 'org.springframework.web.multipart.commons.CommonsMultipartFile' to required type 'byte' for property 'cp_pic[0]': PropertyEditor [org.springframework.beans.propertyeditors.CustomNumberEditor] returned inappropriate value of type 'org.springframework.web.multipart.commons.CommonsMultipartFile']
2020-11-26 22:01:19,513 DEBUG (org.springframework.web.servlet.DispatcherServlet:1076) - Null ModelAndView returned to DispatcherServlet with name 'dispatcher': assuming HandlerAdapter completed request handling
2020-11-26 22:01:19,514 DEBUG (org.springframework.web.multipart.commons.CommonsMultipartResolver:322) - Cleaning up multipart file [cp_pic] with original filename [default.jpg], stored at [D:\JAVA_EE\大三上_Spring\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\cpinfo\upload_03295c31_f743_4a5f_99ca_b184e58f79ba_00000003.tmp]
2020-11-26 22:01:19,515 DEBUG (org.springframework.web.servlet.DispatcherServlet:1000) - Successfully completed request
上一篇:图像增强—空间滤波器


下一篇:CSDN markdown编辑器添加图片时的左对齐、居中、右对齐&并排显示