When the POST request
@RequestBody -> JSON string portion
@RequestParam -> request parameter part
application / json pattern of FIG.
form-data, x-www-form-urlencoded pattern of FIG.
1, from the content-type aspects summarized:
① Data-form, X-form-urlencoded WWW-: not use @RequestBody; can @RequestParam. See postman pattern, when these two approaches are not json string section.
② application / json: json string portion may be @RequestBody; url the back parameters can @RequestParam?. See the pattern postman
2, from two kinds of ways summary notes:
@RequestBody
(
@RequestParam
(
(
(@RequestParam Object object)
不管application/json、form-data、x-www-form-urlencoded都不可用
Neither @RequestBody nor @RequestParam, which receives no parameter is specified way
(Map map)
(Object object) application/json时候:json字符串部分不可用,url中的?后面添加参数不可用。 因为没有指定,它也不知道到底是用json字符串部分还是?后面添加参数部分,所以干脆都不可以用 form-data、x-www-form-urlencoded时都不可用,见图二 (HttpServletRequest request) application/json不可用 form-data、x-www-form-urlencoded时可用
GET request
@RequestBody
RequestBody -- Map / Object
GET请求中不可以使用
@RequestParam
(
(
(
When using a GET request by adding postman? Behind the argument, do not own a fight in a url, click the Params, in the following key-value input is automatically spliced to the url
For chestnuts
upload a file that contains a figure out of the two-part ring
If so, there is no @RequestParam, then the parameter url? After you get
如果control中这样接收,本来想formData只接收url?后的参数,结果将{ "retCode": null, "data": true }这部分内容也拿到了,真实意外之喜。字符串这部分内容还可以从request中取到,见下面完整方法。
完整方法
/**
* 导入
*/
作者:墨色尘埃
链接:https://www.jianshu.com/p/4981911d5e15