org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type ‘Java.lang.String’ to required type ‘org.springframework.web.multipart.commons.CommonsMultipartFile

使用表单上传文件的时候报错:

1
2
3
4
5
HTTP Status 500 - Failed to convert value of type 'java.lang.String' to required type 'org.springframework.web.multipart.MultipartFile';

nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [org.springframework.web.multipart.MultipartFile]: no matching editors or conversion strategy found

org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type 'Java.lang.String' to required type 'org.springframework.web.multipart.commons.CommonsMultipartFile'

是因为没有设置在multipart/form-data 模式 springMVC 无法进行有效的转换

完整的设置为:

1
<form method="post" enctype='multipart/form-data' action="<%=path%>/mng/news/doChangeNews.html">

即可解决

ˆ Back To Top