forked from cho-log/spring-learning-test
-
Notifications
You must be signed in to change notification settings - Fork 5
[spring-jdbc-1] haon.lee(이민성) 과제 제출합니다. #37
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
Open
msung99
wants to merge
8
commits into
Japring-Study:haon/spring-jdbc-1
Choose a base branch
from
msung99:haon/spring-jdbc-1
base: haon/spring-jdbc-1
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+44
−14
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
14e19cf
feat: queryForObject 기능 구현
msung99 65c16db
feat: rowMapper 기능 구현
msung99 8089d70
feat: List with RowMapper 기능 구현
msung99 4d1f848
feat: getLastName 기능 구현
msung99 7f28589
feat: findCustomerByFirstName 기능 구현
msung99 a649846
feat: insert 기능 구현
msung99 400f85d
feat: delete 기능 구현
msung99 8f7ec57
feat: insertWithKeyHolder 기능 구현
msung99 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,26 +33,32 @@ public UpdatingDAO(JdbcTemplate jdbcTemplate) { | |
| */ | ||
| public void insert(Customer customer) { | ||
| //todo: customer를 디비에 저장하기 | ||
| jdbcTemplate.update("insert into customers (first_name, last_name) values (?, ?)", | ||
| customer.getFirstName(), customer.getLastName()); | ||
| } | ||
| /** | ||
| * public int update(String sql, @Nullable Object... args) | ||
| */ | ||
| public int delete(Long id) { | ||
| //todo: id에 해당하는 customer를 지우고, 해당 쿼리에 영향받는 row 수반환하기 | ||
| return 0; | ||
| return jdbcTemplate.update("delete from customers where id = ?", Long.valueOf(id)); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 제가 아직 자바에 익숙치 않은데, 이렇게도 코드를 간략하게 작성할 수 있음에 감탄하고 덕분에 한 수 배워갑니다~! |
||
| } | ||
|
|
||
| /** | ||
| * public int update(final PreparedStatementCreator psc, final KeyHolder generatedKeyHolder) | ||
| */ | ||
| public Long insertWithKeyHolder(Customer customer) { | ||
| String sql = "insert into customers (first_name, last_name) values (?, ?)"; | ||
| KeyHolder keyHolder = new GeneratedKeyHolder(); | ||
|
|
||
| //todo : keyHolder에 대해 학습하고, Customer를 저장후 저장된 Customer의 id를 반환하기 | ||
| jdbcTemplate.update(connection -> { | ||
| PreparedStatement ps = connection.prepareStatement( | ||
| "insert into customers (first_name, last_name) values (?, ?)", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 예약어는 대문자 사용이 좋아보입니다!! |
||
| new String[]{"id"}); | ||
| ps.setString(1, customer.getFirstName()); | ||
| ps.setString(2, customer.getLastName()); | ||
| return ps; | ||
| }, keyHolder); | ||
|
|
||
| Long id = keyHolder.getKey().longValue(); | ||
|
|
||
| return keyHolder.getKey().longValue(); | ||
| return id; | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
가독성을 위해 SQL 예약어(SELECT, FROM 등)은 대문자로 작성하시는 것이 좋을 것 같습니다!