springmvc与content-type

发现如下现象,当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中吗

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值