spring axios对应传参方式

Spring注解对应传参

@RequestParam(@QueryParam)

路径传参(query)对应, 也是默认传参注解,@QueryParam是JAX-RS的注解

   @GetMapping(value = "/hello")
    public ResponseEntity getUser(@RequestParam String username){  
    }

对应url

http://lcoalhost:8080/hello?username=1111

@RequestBody

来获取post提交消息主体中的参数值,并且参数值为json格式,不可以是表单格式提交的参数
代码

    @PostMapping
    public ResponseEntity<Record> add(@RequestBody Record record) {
        return ResponseEntity.ok(this.recordService.insert(record));
    }

请求

POST http://localhost:5138/record/
Content-Type: application/json

{
  "objective": 1.0,
  "objRate": 1.0,
  "objDate": "2022/1/8 12:05:00",
  "outputPrice": 1.0,
}

@PathVariable(@PathParam)

url路径中的参数,@PathParam是JAX-RS注解

@DeleteMapping(value = "/job/{id}")
    public ResponseEntity delete(@PathVariable(value = "id", required = false, defaultValue = "0") Long id){
    
    }

http://localhost:8080/job/yaya

axios

axios.post("/a38/record/",
            {
              params: {id: this.record.id} // 对应@RequestParam(query)参数
              date:{
              	paramName: value,
            	pn: val
            	}  // 对应@RequestBody参数
            }).then(req => {
          _this.findRecordByStrategyId()
        }, err => {
          console.log(err)
        })
      }).catch((_) => {
      })

版权声明:本文为weixin_43884534原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。