Field error in object 'entry' on field 'file': rejected value [org.springframework.web.multipart.com

当用ssm框架进行文件上传遇到的问题为:Field error in object 'entry' on field 'file': rejected value [org.springframework.web.multipart.commons.CommonsMultipartFile@4c6deff6]; codes [typeMismatch.entry.file,typeMismatch.file,typeMismatch.java.lang.String,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [entry.file,file]; arguments []; default message [file]]; default message [Failed to convert property value of type 'org.springframework.web.multipart.commons.CommonsMultipartFile' to required type 'java.lang.String' for property 'file'; 

后来在网上找了很多答案,发现都没有解决问题,最后才发现原来是文件上传对应input 中的name=“file”所造成的之前的代码是:

controller 中的处理方法代码:

最终运行造成的结果是:

解决办法:

把file对应的input中的name改成name=“filepath” 对应的controller中的参数也要进行对应的更改

更改后的代码为:

controller:

运行后的结果成功上传!

猜你喜欢

转载自my.oschina.net/u/3569034/blog/1808962