由於spring的RequestParam注解接收的參數是來自於requestHeader中,即請求頭,也就是在url中,格式為xxx?username=123&password=456,而RequestBody注解接收的參數則是來自於requestBody中,即請求體中。
因此綜上所述,如果為get請求時,后台接收參數的注解應該為RequestParam,如果為post請求時,則后台接收參數的注解就是為RequestBody。
兩個地址:
地址① http://localhost:8989/SSSP/emps?pageNo=2
地址② http://localhost:8989/SSSP/emp/7
如果想獲取地址①中的 pageNo的值 ‘2’ ,則使用 @RequestParam ,
如果想獲取地址②中的 emp/7 中的 ‘7 ’ 則使用 @PathVariable
@RequestMapping(value = "/add", method = RequestMethod.POST)
public AjaxResult save(@RequestBody Product product) {
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public Product get(@PathVariable(value = "id", required = true) Long id)
-
-
public String edit(@PathVariable("id")Integer id,Map<String , O
-
-
public String list(@RequestParam(value="pageNo",required=false,
-