-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Spring JDBC] 김이화 미션 제출합니다. #295
Conversation
간단하게 코멘트 남겼습니당~ |
@Controller | ||
public class WelcomeController { | ||
@GetMapping("/") | ||
public String welcome() { | ||
return "index"; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
홈페이지 컨트롤러와 CR(U)D 컨트롤러를 따로 나눈 거 좋아보여요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
커스텀 예외처리 멋있어용👍👍
public class ReservationController { | ||
private AtomicLong index = new AtomicLong(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
헉 지워서 제출하겠습니다
public Reservation findReservationById(Long id) { | ||
String sql = "SELECT id, name, date, time FROM reservation where id = ?"; | ||
try { | ||
return jdbcTemplate.queryForObject(sql, rowMapper, id); | ||
} catch (EmptyResultDataAccessException e) { | ||
throw new NotFoundReservationException(id); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오 원래 DAO에 대해서 잘 알고 있었나요? 능숙해보여요
EmptyResultDataAccessException
가 무슨 예외인지 궁금합니당
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아뇨 초록 스터디 학습테스트에서 열심히 해봤는데도 사용하는데 어려움이 많았습니다 ㅠㅠ
EmptyResultDataAccessException
는 JDBC를 사용할 때 데이터베이스에서 조회 결과가 없을 경우 발생하는 예외라고 해서 사용했습니다!
@GetMapping("/{id}") | ||
@ResponseBody | ||
public Reservation findReservationById(@PathVariable Long id) { | ||
return reservationRepository.findReservationById(id); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
여기에서는 왜 따로 ResponseEntity 활용을 안했는지 궁금합니당
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ResponseEntity
를 사용하지 않아도 예외가 발생하면 GlobalExceptionHandler
에서 처리해줘서 크게 문제가 안 된다고 생각했습니다
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
패키지 구분이 깔끔하게 잘 된 것 같아요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exception 명확하게 구분한 것 좋은 것 같아요!
} | ||
} | ||
|
||
public Reservation insert(Reservation reservation) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@transactional에 대해서 공부해봐도 좋을 것 같아요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Transactional
로 지정된 메소드가 호출될 때 트랜잭션이 시작되고, 메소드 실행이 끝나면 트랜잭션이 커밋되거나 롤백 됩니다.
트랜잭션 커밋은 트랜잭션 내의 모든 작업이 성공적으로 완료되어 데이터베이스에 영구적으로 반영되는 것을 의미하고 트랜잭션 롤백은 트랜잭션 내의 작업 중 하나라도 실패하거나 문제가 발생했을 때 트랜잭션이 시작된 이후의 모든 변경 사항을 취소하는 것을 의미합니다.
@Transactional
은 데이터베이스 작업에서 원자성, 일관성, 고립성, 지속성. 즉, ACID 속성을 보장하기 위해 사용된다고 합니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RequestDto와 ResponseDto를 만들어 엔티티 분리하면 더 좋을 것 같아요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[spring core]에 리팩토링 해서 만들었습니다!
if (reservation.getTime() == null || reservation.getTime().isEmpty()) { | ||
throw new InvalidReservationException("time", "시간이 필요합니다."); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
validateReservation 메소드 분리 할 수 있지 않을까요?! 중복된 코드를 줄이면 가독성이 좋아질 것 같아요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[spring core]에 리팩토링 해서 넣었습니다. 클래스로 나눠서 예외 처리 패키지에 넣었는데, 이걸 말씀하시는 게 맞을까요?
mvc 리팩토링이랑 jdbc 한 번에 해서 올리게 되었습니다..