<dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> </dependency> @RestController @RequestMapping("/users") public class UserController { @Autowired private UserService userService; @GetMapping public List<User> getAllUsers() { return userService.getAllUsers(); } @PostMapping public void createUser(@RequestBody User user) { userService.createUser(user); } } @Service public class UserService { private List<User> users = new ArrayList<>(); public List<User> getAllUsers() { return users; } public void createUser(User user) { users.add(user); } } @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }


上一篇:
下一篇:
切换中文