在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Java/ springmvc處理圖片上傳時使用MultipartFile 接收為null。

springmvc處理圖片上傳時使用MultipartFile 接收為null。

1.使用富文本編輯器上傳圖片,在controller中使用MultipartFile接收為null。debug發(fā)現(xiàn),request經(jīng)過dispatcherServlet是有值的。而且可以正常映射到方法中去。
2.springmvc中的配置:


<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
    <!-- 設(shè)定默認編碼 -->
    <property name="defaultEncoding" value="UTF-8"></property>
    <!-- 設(shè)定文件上傳的最大值5MB,5*1024*1024 -->
    <property name="maxUploadSize" value="5242880"></property>
</bean>

3.DEBUG信息:
DEBUG [http-bio-90-exec-10] - DispatcherServlet with name 'web' processing GET request for [/js/kindeditor-4.1.10/lang/zh_CN.js]
DEBUG [http-bio-90-exec-10] - Looking up handler method for path /js/kindeditor-4.1.10/lang/zh_CN.js
DEBUG [http-bio-90-exec-10] - Did not find handler method for [/js/kindeditor-4.1.10/lang/zh_CN.js]
DEBUG [http-bio-90-exec-10] - Matching patterns for request [/js/kindeditor-4.1.10/lang/zh_CN.js] are [/js/**]
DEBUG [http-bio-90-exec-10] - URI Template variables for request [/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] to HandlerExecutionChain with handler [ResourceHttpRequestHandler [locations=[ServletContext resource [/js/]], resolvers=[org.springframework.web.servlet.resource.PathResourceResolver@105fda6b]]] and 1 interceptor
DEBUG [http-bio-90-exec-10] - Last-Modified value for [/js/kindeditor-4.1.10/lang/zh_CN.js] is: -1
DEBUG [http-bio-90-exec-10] - Null ModelAndView returned to DispatcherServlet with name 'web': assuming HandlerAdapter completed request handling
DEBUG [http-bio-90-exec-10] - Successfully completed request
DEBUG [http-bio-90-exec-10] - DispatcherServlet with name 'web' processing GET request for [/js/kindeditor-4.1.10/plugins/multiimage/images/swfupload.swf]
DEBUG [http-bio-90-exec-10] - Looking up handler method for path /js/kindeditor-4.1.10/plugins/multiimage/images/swfupload.swf
DEBUG [http-bio-90-exec-10] - Did not find handler method for [/js/kindeditor-4.1.10/plugins/multiimage/images/swfupload.swf]
DEBUG [http-bio-90-exec-10] - Matching patterns for request [/js/kindeditor-4.1.10/plugins/multiimage/images/swfupload.swf] are [/js/**]
DEBUG [http-bio-90-exec-10] - URI Template variables for request [/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] to HandlerExecutionChain with handler [ResourceHttpRequestHandler [locations=[ServletContext resource [/js/]], resolvers=[org.springframework.web.servlet.resource.PathResourceResolver@105fda6b]]] and 1 interceptor
DEBUG [http-bio-90-exec-10] - Last-Modified value for [/js/kindeditor-4.1.10/plugins/multiimage/images/swfupload.swf] is: -1
DEBUG [http-bio-90-exec-10] - Null ModelAndView returned to DispatcherServlet with name 'web': assuming HandlerAdapter completed request handling
DEBUG [http-bio-90-exec-10] - Successfully completed request
DEBUG [http-bio-90-exec-10] - DispatcherServlet with name 'web' processing POST request for [/pic/upload]
DEBUG [http-bio-90-exec-10] - Found multipart file [uploadFile] of size 345594 bytes with original filename [natalie.png], stored at [D:ideaWorkspace2e3mallwebtargettomcatworkTomcatlocalhost_upload_605390ea_b9db_44ee_9bf4_b426b27db686_00000001.tmp]
DEBUG [http-bio-90-exec-10] - Looking up handler method for path /pic/upload
DEBUG [http-bio-90-exec-10] - Returning handler method [public java.util.Map cn.e3mall.controller.PictureController.fileUpload(org.springframework.web.multipart.MultipartFile)]
DEBUG [http-bio-90-exec-10] - Returning cached instance of singleton bean 'pictureController'
DEBUG [http-bio-90-exec-10] - Skip CORS processing, request is a same-origin one

回答
編輯回答
不二心

發(fā)完一分鐘就意識到了這犯的是低級錯誤,在controller的方法形參類型雖然為MultipartFile,但參數(shù)名必須為uploadFile,否則無法映射成功,自然接收不到request域中的對象,果然不要出了什么事情立馬去網(wǎng)上找答案。很多做法完全是背道而馳。
謹以此為戒。

2017年6月30日 15:13
編輯回答
生性

我們學的時候說可以改變參數(shù)名啊 現(xiàn)在都是attach 實現(xiàn)信息新增的時候可以上傳成功 但是在修改信息的時候 將原來的舊圖片刪除 重新新增一個圖片的時候就獲取不到值了 是怎么回事 求大神指教

2017年11月2日 03:21