关于前后端分离,post与get后台接收参数注解
由于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) @RequestMapping(value="/emp/{id}",method=RequestMethod.GET) public String edit(@PathVariable("id")Integer id,Map<String , O @RequestMapping("/emps") public String list(@RequestParam(value="pageNo",required=false,
一般来说查询多用于get请求,修改新增使用post请求
转自:https://www.cnblogs.com/wgyi140724-/p/10678891.html