由于spring的RequestParam注解接收的参数是来自于requestHeader中,即请求头,也就是在url中,格式为xxx?username=123&password=456,而RequestBody注解接收的参数则是来自于requestBody中,即请求体中。

因此综上所述,如果为get请求时,后台接收参数的注解应该为RequestParam,如果为post请求时,则后台接收参数的注解就是为RequestBody。

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

两个地址:
地址① 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,

 

 

 

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄