美文网首页
@RequestParam与@RequestBody使用对比

@RequestParam与@RequestBody使用对比

作者: 秀萝卜 | 来源:发表于2021-01-08 12:11 被阅读0次

1.RequestParam
用来处理Content-Type: 为 application/x-www-form-urlencoded编码的内容。
(Http协议中,如果不指定Content-Type,则默认传递的参数就是application/x-www-form-urlencoded类型)

2.RequestBody
一般用来处理非Content-Type: application/x-www-form-urlencoded编码格式的数据。
GET请求中,不支持rRequestBody

3.总结:
  1. form-data、x-www-form-urlencoded:不可以用@RequestBody;
  2. application/json:json字符串部分可以用@RequestBody;url中的?后面参数可以用@RequestParam
  3. get请求中不能用@RequestBody注解

this.axios({
    method: "POST",
    url: `${API_HOST}/api/bind/index`,
    data: obj,
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
    }
}).then(function(res) {
    console.log(res);
});

相关文章

网友评论

      本文标题:@RequestParam与@RequestBody使用对比

      本文链接:https://www.haomeiwen.com/subject/husinktx.html