| package com.example.g8backend.controller; |
| import com.example.g8backend.entity.User; |
| import com.example.g8backend.service.IUserService; |
| import org.springframework.beans.factory.annotation.Autowired; |
| import org.springframework.web.bind.annotation.*; |
| @RequestMapping("/users") |
| public class UserController { |
| private IUserService userService; |
| public List<User> getUsers() { |
| return userService.list(); |
| public User getUserById(@PathVariable Long id) { |
| return userService.getById(id); |
| @GetMapping("/name/{name}") |
| public User getUserByName(@PathVariable String name) { |
| return userService.getUserByName(name); |
| public boolean addUser(@RequestBody User user) { |
| System.out.println(user); |
| return userService.save(user); |
| public boolean updateUser(@RequestBody User user) { |
| return userService.updateById(user); |
| public boolean deleteUser(@PathVariable Long id) { |
| return userService.removeById(id); |