get
@PathVariable
获取路径参数。即url/{id}这种形式。
@RequestParam
获取查询参数。即url?name=这种形式
@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);
}
post
vue
let obj = {};
obj['xxx'] =xxx;
axios.post(url, obj).then(response => {
xxx
});
@RequestBody
@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"));
}
网友评论