发现如下现象,当content-type 为form-data的时候,如果没有文件上传的设置。1.无法正常的绑定命令对象
@RequestMapping("param")
public Object param(User user, @RequestHeader HttpHeaders headers){
Set<String> keys = headers.keySet();
for(String key: keys){
System.out.println(key+"--"+headers.get(key));
}
return user;
}
需要配置
<!-- 文件上传处理 -->
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- one of the properties available; the maximum file size in bytes -->
<property name="maxUploadSize" value="2097152"/>
</bean>
2.而且如果在命令对象中有@RequestBody。会有警告,也无法访问。
org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver.handleHttpMessageNotReadable Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing: public java.lang.Object tobin.common.CommonController.param(tobin.common.User,org.springframework.http.HttpHeaders,java.lang.String)
没有 request body。难道form-data方式没有将请求参数放到body中吗