1. 程式人生 > >@RequestParam 和 @RequestBody 的區別

@RequestParam 和 @RequestBody 的區別

@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) {

}