SpringMvc上傳文件報錯[org.springframework.web.multipart.MultipartFile]: Specified class is an interface

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.multipart.MultipartFile]: Specified class is an interface

在報這個問題之前,首先要注意

前臺頁面

  1. 提交文件的input標籤是否具有name屬性
  2. 表單是否是以POST方式提交
  3. form標籤上是否有enctype="multipart/form-data"

後臺代碼

  1. 攔截的方法接收參數屬性是否是MultipartFile ,名稱是否和前臺name屬性一致
  2. 是否在配置文件中配置下面一句話

<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"></bean>

id名稱必須一致

如果以上,都有做到,請在攔截方法中的MultipartFile 類型的參數前加上@RequestParam註解。

補充一點:Springmvc.xml中<mvc:annotation-driven/>是否書寫了。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章