-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserController.java
More file actions
37 lines (29 loc) · 933 Bytes
/
UserController.java
File metadata and controls
37 lines (29 loc) · 933 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package user;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/api")
public class UserController {
@Autowired
private UserService userService;
@GetMapping("/users")
public List<User> getAllUsers() {
return userService.getAllUsers();
}
@PutMapping("/{id}/{userName}")
public void addUser(@PathVariable Integer id, @PathVariable String userName) {
User user = new User();
user.setId(id);
user.setUserName(userName);
userService.addUser(user);
}
@PostMapping("/{id}/{data}")
public void updateUser(@PathVariable Integer id, @PathVariable String data) {
userService.updateUser(id, data);
}
@DeleteMapping("/{id}")
public void deleteUser(@PathVariable Integer id) {
userService.deleteUser(id);
}
}