-
Notifications
You must be signed in to change notification settings - Fork 300
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
[ JDBC 1단계 ] 박스터 미션 제출합니다. #261
Conversation
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.
안뇽하세요 빡스터~ 빡스터가 그렇게 기다리던 리뷰가 도착했습니다 ㅋㅋ jdbctemplate도 잘 분리해주셔서 크게 코멘트할 건 없었습니다! 간단하게 살펴봐주세요!
try { | ||
if (pstmt != null) { | ||
pstmt.close(); | ||
} | ||
} catch (SQLException ignored) { | ||
} | ||
|
||
try { | ||
if (conn != null) { | ||
conn.close(); | ||
} | ||
} catch (SQLException ignored) { | ||
} | ||
} |
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.
위에 존재하는 try문은 PrepareStatement의 예외를 처리하고, 아래에 존재하는 try문은 Connection에 대한 예외를 처리하는 구문인데 메서드마다 반복되고 있네요! 중복을 줄여볼 수 있을까요?
분리하면 아래와 같이 try문에 한번에 정의할 수도 있겠네요!
try (
final Connection connection = dataSource.getConnection();
final PreparedStatement pstmt = connection.prepareStatement(sql)
) {
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.
요건 ㅎㅎ 2단계에 하려고 아껴뒀습니다 ㅎㅎ
} | ||
} | ||
|
||
public <T> T queryForObject(String sql, RowMapper<T> rowMapper, Object... args) { |
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.
저는 QueryForObject의 파라미터를 한 개라고 가정하고 만들었는데, 조건을 여러개라고 생각한 점이 인상깊네요! 저도 반영해봐야겠습니다 ㅋㅋ
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 UserDao(final JdbcTemplate jdbcTemplate) { | ||
this.dataSource = null; | ||
this.jdbcTemplate = jdbcTemplate; | ||
} | ||
|
||
public void insert(final User user) { | ||
final var sql = "insert into users (account, password, email) values (?, ?, ?)"; |
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.
박스터는 var 타입을 선호하시나요? 타입을 선언하는것에 비해 어떤 장점이 있나요??
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.
저는 var가 좋아요 굳이 명시하지 않아도 알 수 있다고 생각해서요 하지만 지금은 그냥 복사 붙여넣기를 해서 var를 사용했습니다..
} | ||
|
||
public User findByAccount(final String account) { | ||
// todo | ||
return null; | ||
final var sql = "select id, account, password, email from users where account = ?"; |
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.
"select * from users where account = ?";
위와 같이 *로도 받을 수 있을 것 같은데, 하나씩 선언하신 이유가 있나요?
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.
이렇게 한다면 데이터베이스 칼럼의 변경에 유연하지 못하다고 생각했습니디 만약 그렇게 받을 거면 jpa로 편하게 받을 것 같아요
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.
역시 빡스터~ 소문대로 엄청난 인재네요 다음 단계도 화이팅~~
안녕하세요 베베
1단계에서는 기능 동작에 우선을 두고 작업을 했습니다.
2단계에서 코드의 중복이나 이러한 부분들을 제거하도록 하겠습니다
감사합니다.