SpringBoot ViewControl参数接收
客户端 | 服务端 |
Map map=new HashMap(); map.put("name","123"); String jsonStr = new Gson().toJson(map); RequestBody requestBody = RequestBody.create(MediaType.parse ("application/json; charset=utf-8"), jsonStr); | @RequestBody F6CarFDTO data @Data class F6CarFDTO{ public String name; } |
http://localhost:8080/demo/123?name=suki_rong | @GetMapping("/demo/{id}") public void demo(@PathVariable(name = "id") String id, @RequestParam(name = "name") String name) { System.out.println("id="+id); System.out.println("name="+name); } |
![]() | @PostMapping(path = "/demo1") public void demo1(@RequestBody Person person) { System.out.println(person.toString()); } 也可以 @PostMapping(path = "/demo1") public void demo1(@RequestBody Map<String, String> person) { System.out.println(person.get("name")); } |
![]() | @PostMapping(path = "/demo2") public void demo2(Person person) { System.out.println(person.toString()); } |
请求头参数以及Cookie1、@RequestHeader2、@CookieValue | @GetMapping("/demo3") @GetMapping("/demo3") |
{"vinCode":"11111111111"} | @PostMapping("carModelVinCodeByF6") public ResultInfo<List<CarModels>> carModelVinCodeByF6(@RequestBodyExtract("vinCode") String vinCode) { List<CarModels> carModels = f6CarModelService.carModelVinCodeByF6(vinCode); return ResultInfo.success(carModels); } RequestBodyExtract 有时候会接收不到参数 |