zoukankan      html  css  js  c++  java
  • 关于前后端分离,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,
    
    
     
    
    
    
  • 相关阅读:
    DBG
    gdb Debugging Full Example
    Java Warmup
    Dtrace for Linux 2016
    分布式系统理论进阶
    Java theory and practice
    Dealing with InterruptedException
    JVM 虚拟化
    Intro to Filtering with Network Monitor 3.0
    spring 官方文档
  • 原文地址:https://www.cnblogs.com/wgyi140724-/p/10678891.html
Copyright © 2011-2022 走看看