Let's say that we have a UserController class with two GET endpoints:
- /users/{id} endpoint, which returns a User object for a given id
- /users endpoint, which returns List<User>
Java
xxxxxxxxxx
1
26
1
public class User {
2
3
private Integer id;
4
private String name;
5
private Date dateOfBirth;
6
private String city;
7
8
// constructors, getters & setters are ignored
9
}
10
11
12
public class UserController {
13
14
15
UserService userService;
16
17
value = "/user/{id}", method= RequestMethod.GET) (
18
User getUser( ("id") String id){
19
return userService.getUser(id);
20
}
21
22
value = "/users", method= RequestMethod.GET) (
23
List<User> getAllUsers(){
24
return userService.getAllUsers();
25
}
26
}