owo
示例:
@RestController
public class UserController {
@GetMapping("/user/{id}")
public String getUserById(@PathVariable int id) {
System.out.println(id);
return "根据ID获取用户信息";
}
@PostMapping("/user")
public String save(User user) {
return "添加用户";
}
@PutMapping("/user")
public String update(User user) {
return "更新用户";
}
@DeleteMapping("/user/{id}")
public String deleteById(@PathVariable int id) {
System.out.println(id);
return "根据ID删除用户";
}
}
要获取动态路径的参数需要加 @PathVariable
,否则会获取后面的