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>
xxxxxxxxxx
public class User {
private Integer id;
private String name;
private Date dateOfBirth;
private String city;
// constructors, getters & setters are ignored
}
public class UserController {
UserService userService;
value = "/user/{id}", method= RequestMethod.GET) (
User getUser( ("id") String id){
return userService.getUser(id);
}
value = "/users", method= RequestMethod.GET) (
List<User> getAllUsers(){
return userService.getAllUsers();
}
}