📖 学习要点
RESTful API 设计:
GET /api/users - 获取所有用户
GET /api/users/{id} - 获取单个用户
POST /api/users - 创建用户
PUT /api/users/{id} - 更新用户
DELETE /api/users/{id} - 删除用户
Controller 代码示例
@RestController
@RequestMapping("/api/users")
public class UserController {
@GetMapping
public List<User> getAllUsers() { ... }
@GetMapping("/{id}")
public User getUserById(@PathVariable Long id) { ... }
@PostMapping
public User createUser(@RequestBody User user) { ... }
@PutMapping("/{id}")
public User updateUser(@PathVariable Long id, @RequestBody User user) { ... }
@DeleteMapping("/{id}")
public String deleteUser(@PathVariable Long id) { ... }
}