I have a Spring Boot application and this handler method:
@PostMapping("/{id}")
public User create(@PathVariable("id") Long id, @RequestBody User user) {
if (id > 0 && id < 10) {
String fullName = user.getFirstName() + " " + user.getLastName();
user.setId(id);
user.setFullName(fullName);
} else {
//Return 401 ?
}
return userService.save(user);
}
How can I return return 401?
The response JSON should look like:
{
"msg": "empty",
"status" : "401"
}