为了账号安全,请及时绑定邮箱和手机立即绑定

springmvc处理图片上传时使用MultipartFile 接收为null。

springmvc处理图片上传时使用MultipartFile 接收为null。

梦里花落0921 2019-05-24 10:31:49
1.使用富文本编辑器上传图片,在controller中使用MultipartFile接收为null。debug发现,request经过dispatcherServlet是有值的。而且可以正常映射到方法中去。2.springmvc中的配置:3.DEBUG信息:DEBUG[http-bio-90-exec-10]-DispatcherServletwithname'web'processingGETrequestfor[/js/kindeditor-4.1.10/lang/zh_CN.js]DEBUG[http-bio-90-exec-10]-Lookinguphandlermethodforpath/js/kindeditor-4.1.10/lang/zh_CN.jsDEBUG[http-bio-90-exec-10]-Didnotfindhandlermethodfor[/js/kindeditor-4.1.10/lang/zh_CN.js]DEBUG[http-bio-90-exec-10]-Matchingpatternsforrequest[/js/kindeditor-4.1.10/lang/zh_CN.js]are[/js/**]DEBUG[http-bio-90-exec-10]-URITemplatevariablesforrequest[/js/kindeditor-4.1.10/lang/zh_CN.js]are{}DEBUG[http-bio-90-exec-10]-Mapping[/js/kindeditor-4.1.10/lang/zh_CN.js]toHandlerExecutionChainwithhandler[ResourceHttpRequestHandler[locations=[ServletContextresource[/js/]],resolvers=[org.springframework.web.servlet.resource.PathResourceResolver@105fda6b]]]and1interceptorDEBUG[http-bio-90-exec-10]-Last-Modifiedvaluefor[/js/kindeditor-4.1.10/lang/zh_CN.js]is:-1DEBUG[http-bio-90-exec-10]-NullModelAndViewreturnedtoDispatcherServletwithname'web':assumingHandlerAdaptercompletedrequesthandlingDEBUG[http-bio-90-exec-10]-SuccessfullycompletedrequestDEBUG[http-bio-90-exec-10]-DispatcherServletwithname'web'processingGETrequestfor[/js/kindeditor-4.1.10/plugins/multiimage/images/swfupload.swf]DEBUG[http-bio-90-exec-10]-Lookinguphandlermethodforpath/js/kindeditor-4.1.10/plugins/multiimage/images/swfupload.swfDEBUG[http-bio-90-exec-10]-Didnotfindhandlermethodfor[/js/kindeditor-4.1.10/plugins/multiimage/images/swfupload.swf]DEBUG[http-bio-90-exec-10]-Matchingpatternsforrequest[/js/kindeditor-4.1.10/plugins/multiimage/images/swfupload.swf]are[/js/**]DEBUG[http-bio-90-exec-10]-URITemplatevariablesforrequest[/js/kindeditor-4.1.10/plugins/multiimage/images/swfupload.swf]are{}DEBUG[http-bio-90-exec-10]-Mapping[/js/kindeditor-4.1.10/plugins/multiimage/images/swfupload.swf]toHandlerExecutionChainwithhandler[ResourceHttpRequestHandler[locations=[ServletContextresource[/js/]],resolvers=[org.springframework.web.servlet.resource.PathResourceResolver@105fda6b]]]and1interceptorDEBUG[http-bio-90-exec-10]-Last-Modifiedvaluefor[/js/kindeditor-4.1.10/plugins/multiimage/images/swfupload.swf]is:-1DEBUG[http-bio-90-exec-10]-NullModelAndViewreturnedtoDispatcherServletwithname'web':assumingHandlerAdaptercompletedrequesthandlingDEBUG[http-bio-90-exec-10]-SuccessfullycompletedrequestDEBUG[http-bio-90-exec-10]-DispatcherServletwithname'web'processingPOSTrequestfor[/pic/upload]DEBUG[http-bio-90-exec-10]-Foundmultipartfile[uploadFile]ofsize345594byteswithoriginalfilename[natalie.png],storedat[D:ideaWorkspace2e3mallwebtargettomcatworkTomcatlocalhost_upload_605390ea_b9db_44ee_9bf4_b426b27db686_00000001.tmp]DEBUG[http-bio-90-exec-10]-Lookinguphandlermethodforpath/pic/uploadDEBUG[http-bio-90-exec-10]-Returninghandlermethod[publicjava.util.Mapcn.e3mall.controller.PictureController.fileUpload(org.springframework.web.multipart.MultipartFile)]DEBUG[http-bio-90-exec-10]-Returningcachedinstanceofsingletonbean'pictureController'DEBUG[http-bio-90-exec-10]-SkipCORSprocessing,requestisasame-originone
查看完整描述

2 回答

?
蝴蝶刀刀

TA贡献1801条经验 获得超8个赞

发完一分钟就意识到了这犯的是低级错误,在controller的方法形参类型虽然为MultipartFile,但参数名必须为uploadFile,否则无法映射成功,自然接收不到request域中的对象,果然不要出了什么事情立马去网上找答案。很多做法完全是背道而驰。谨以此为戒。
                            
查看完整回答
反对 回复 2019-05-24
?
喵喔喔

TA贡献1735条经验 获得超5个赞

我们学的时候说可以改变参数名啊现在都是attach实现信息新增的时候可以上传成功但是在修改信息的时候将原来的旧图片删除重新新增一个图片的时候就获取不到值了是怎么回事求大神指教
                            
查看完整回答
反对 回复 2019-05-24
  • 2 回答
  • 0 关注
  • 4862 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信