@RequestParam与@RequestBody使用对比

2021-01-08  本文已影响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);
});
上一篇 下一篇

猜你喜欢

热点阅读