2月25日

Controller层扩展
在UserController中补充CRUD接口:
@RestController
@RequestMapping("/user")
public class UserController {
@Autowired
private UserService userService;

@GetMapping("/{id}")
public User getUser(@PathVariable Long id) {
    return userService.getById(id);
}

@PostMapping("/save")
public String saveUser(@RequestBody User user) {
    userService.save(user);
    return "用户信息已保存";
}

@PutMapping("/update")
public String updateUser(@RequestBody User user) {
    userService.update(user);
    return "用户信息已更新";
}

@DeleteMapping("/delete/{id}")
public String deleteUser(@PathVariable Long id) {
    userService.delete(id);
    return "用户信息已删除";
}

@GetMapping("/all")
public List<User> getAllUsers() {
    return userService.getAll();
}

}

add.html:用户添加页面
HTML

添加用户

添加用户



posted @ 2025-02-19 23:54  skurar  阅读(15)  评论(0)    收藏  举报