localhost:8080/users/1234 이렇게 없는 유저를 조회했을때 404로 예외처리를 하고싶음
UserNotFoundException.java (예외 파일 정의)
@ResponseStatus(code = HttpStatus.NOT_FOUND) // 404설정
public class UserNotFoundException extends RuntimeException {
public UserNotFoundException(String message){
super(message);
}
}
UserResource.java ( GET부분 수정)
@GetMapping("/users/{id}")
public User retrieveUser(@PathVariable int id){
User user = service.findOne(id);
if (user == null) //UserDaoService의 findOne 메소드의 리턴
throw new UserNotFoundException("id:"+id);
return user;
}
localhost:8080/users/1234 이렇게 없는 유저를 조회했을때 404로 예외처리를 하고싶음
UserNotFoundException.java (예외 파일 정의)
@ResponseStatus(code = HttpStatus.NOT_FOUND) // 404설정 public class UserNotFoundException extends RuntimeException { public UserNotFoundException(String message){ super(message); } }
UserResource.java ( GET부분 수정)
@GetMapping("/users/{id}") public User retrieveUser(@PathVariable int id){ User user = service.findOne(id); if (user == null) //UserDaoService의 findOne 메소드의 리턴 throw new UserNotFoundException("id:"+id); return user; }