關於前后端分離,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,

 

 

 
        

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM