在同步提交的时候,Spring把空上传是做null来处理的,而在异步提交的时候,Spring把文件域的值当作空字符串看待的。在Spring做请求转换的时候(request–>MultipartHttpServletRequest)底层的TypeConverter接口实现对null和""是做了不同操作的。源码就不贴了,有兴趣的伙伴可以自行从:org.springframework.web.multipart.commons.CommonsMultipartResolver
这个类跟下去,就会发现差异。
<mvc:annotation-driven conversion-service=“conversionService” />必须配置在最后,否则不生效,如果上面有其他的mvc:annotation-driven要把它们合成一个
如:
<mvc:annotation-driven conversion-service="conversionService" validator="validator" >
<mvc:message-converters>
<ref bean="messageConverter" />
</mvc:message-converters>
</mvc:annotation-driven>
(直接用一个<mvc:annotation-driven />可能可以,并没有试过)