forked from cho-log/spring-learning-test
-
Notifications
You must be signed in to change notification settings - Fork 5
[spring-jdbc-1] ivy.lee(이다예) 과제 제출합니다. #40
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
dayaelee
wants to merge
12
commits into
Japring-Study:ivy/spring-jdbc-1
Choose a base branch
from
dayaelee:ivy/spring-jdbc-1
base: ivy/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.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
0ba7b98
[8월 1일 숙제]spring-mvc-1
dayaelee 257d8a7
[spring-mvc-1] ivy.lee(이다예) 과제 제출합니다.
dayaelee 18c9ca4
[spring-mvc-2] ivy.lee(이다예) 과제 제출합니다.
dayaelee 865a56d
3.1 Object with Count, customers 디비에 포함되어있는 row가 몇개인지 확인하는 기능 구현
dayaelee 3feeae8
3.2 Object with Parameter, 주어진 Id에 해당하는 customers의 lastName을 반환
dayaelee 0bea06b
3.3 Object with RowMapper, 주어진 Id에 해당하는 customer를 객체로 반환
dayaelee 4e08f37
4.1 List with RowMapper, 저장된 모든 Customers를 list형태로 반환
dayaelee cfde886
3.3 Object with RowMapper, 과제 수행후 오타 수정
dayaelee 45ef260
5.1 Update (INSERT), customer를 디비에 저장하기
dayaelee 9ee4f02
4.1 List with RowMapper, firstName을 기준으로 customer를 list형태로 반환
dayaelee b58ac33
5.2 Update (DELETE), id에 해당하는 customer를 지우고, 해당 쿼리에 영향받는 row 수반환하기
dayaelee b64c113
5.3 KeyHolder, keyHolder에 대해 학습하고, Customer를 저장후 저장된 Customer의 id를 반환하기
dayaelee 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 |
|---|---|---|
|
|
@@ -8,6 +8,8 @@ | |
|
|
||
| import java.sql.PreparedStatement; | ||
|
|
||
| import static java.lang.String.valueOf; | ||
|
|
||
| @Repository | ||
| public class UpdatingDAO { | ||
| private JdbcTemplate jdbcTemplate; | ||
|
|
@@ -32,14 +34,17 @@ public UpdatingDAO(JdbcTemplate jdbcTemplate) { | |
| * public int update(String sql, @Nullable Object... args) | ||
| */ | ||
| public void insert(Customer customer) { | ||
| //todo: customer를 디비에 저장하기 | ||
| String sql = "insert into customers (first_name, last_name) values (?, ?)"; | ||
| jdbcTemplate.update(sql, customer.getFirstName(), customer.getLastName()); | ||
| } | ||
| /** | ||
| * public int update(String sql, @Nullable Object... args) | ||
| */ | ||
| public int delete(Long id) { | ||
| //todo: id에 해당하는 customer를 지우고, 해당 쿼리에 영향받는 row 수반환하기 | ||
| return 0; | ||
| String sql = "delete from customers where id = ?"; | ||
| Integer affectedRow = jdbcTemplate.update(sql, Long.valueOf(id)); | ||
|
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.
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. 간결하게 ' return jdbcTemplate.update(sql, id);' 로 가도 괜찮을 것 같습니다! |
||
|
|
||
| return affectedRow; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -49,7 +54,14 @@ 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( | ||
| sql, | ||
| new String[]{"id"}); | ||
| ps.setString(1, customer.getFirstName()); | ||
| ps.setString(2, customer.getLastName()); | ||
| return ps; | ||
| }, keyHolder); | ||
|
|
||
| Long id = keyHolder.getKey().longValue(); | ||
|
|
||
|
|
||
23 changes: 19 additions & 4 deletions
23
spring-mvc-1/initial/src/main/java/cholog/MemberController.java
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 |
|---|---|---|
| @@ -1,18 +1,33 @@ | ||
| package cholog; | ||
|
|
||
| import org.springframework.stereotype.Controller; | ||
| import org.springframework.ui.Model; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.RequestParam; | ||
| import org.springframework.web.bind.annotation.ResponseBody; | ||
|
|
||
| @Controller | ||
| public class MemberController { | ||
|
|
||
| public String world() { | ||
| @GetMapping("/hello") | ||
| public String world(@RequestParam(name = "name", required = false) String name, Model model) { | ||
| // TODO: /hello 요청 시 resources/templates/static.html 페이지가 응답할 수 있도록 설정하세요. | ||
| // TODO: 쿼리 파라미터로 name 요청이 들어왔을 때 해당 값을 hello.html에서 사용할 수 있도록 하세요. | ||
| return null; | ||
| if (name == null){ | ||
| // 쿼리 파라미터가 없는 경우 | ||
| return "static"; | ||
| } else { | ||
| // 쿼리 파라미터가 있는 경우. | ||
| model.addAttribute("name", name); | ||
| return "hello"; | ||
| } | ||
|
|
||
|
|
||
| } | ||
|
|
||
| @GetMapping("/json") | ||
| @ResponseBody | ||
| public Person json() { | ||
| // TODO: /json 요청 시 {"name": "brown", "age": 20} 데이터를 응답할 수 있도록 설정하세요. | ||
| return null; | ||
| return new Person("brown", 20); | ||
| } | ||
| } |
File renamed without changes.
File renamed without changes.
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
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.
queryForObject함수가 단일 객체를 반환한다는 점에서customers라는 복수의 이름 대신 customer로 바꿔도 되지 않을까 생각합니다!