@RequestParam 和 @RequestBody 的区别

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wuzhong8809/article/details/84028831

@RequestParam

Annotation which indicates that a method parameter should be bound to a web request parameter.

HTTP请求参数

比如

http://xx.com/image/detail?id=5

可以通过以下方式拿到参数值

public getImageDetailByID(@RequestParam("id")  int id) {

}

@RequestBody

Annotation indicating a method parameter should be bound to the body of the web request.

消息正文中携带的key-value键值对

比如

一个post请求的正文是JSON格式的

{"id":"8"}

可以通过以下方式拿到参数值

public getImageDetailByID(@RequestBody  int id) {

}

猜你喜欢

转载自blog.csdn.net/wuzhong8809/article/details/84028831