-
Notifications
You must be signed in to change notification settings - Fork 27
[김예슬_BackEnd] 11주차 과제 제출합니다. #7
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
base: main
Are you sure you want to change the base?
Conversation
DHkimgit
left a comment
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 void setContent(String content) { | ||
| this.content = content; | ||
| } | ||
|
|
||
|
|
||
|
|
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 void setId(Long id) { | ||
| this.id = 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.
public 메소드로 정의된 setter가 가진 문제점은 무엇일까요? setter를 사용하지 않는다면 객체의 값을 변경해야 할 때 어떻게 해야 할지도 고민해보시면 좋을 것 같아요.
| public class ArticleController { | ||
|
|
||
| private final Map<Long, Article> articles = new ConcurrentHashMap<>(); | ||
| private final AtomicLong idGenerator = 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.
AtomicLong 을 사용해 주셨네요! Long과 어떤 차이가 있나요?
| if (article == null) { | ||
| return ResponseEntity.notFound().build(); | ||
| } | ||
| return ResponseEntity.ok().body(article); |
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 사용 좋습니다.
Article 객체가 그대로 반환되고 있는데, dto에 대해서 공부해보시면 좋을 것 같아요. dto를 사용하는 이유가 무엇일까요?
|
|
||
| public class introduce2 { |
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.
클래스 이름을 소문자로 하신 이유가 있나요? 이름을 어떻게 지어야 하는지 고민이 되신다면 자바 진영에서 사용하는 명명 규칙(Naming Coonvention)에 대해서 알아보세요!
|
|
||
| private final Map<Long, Article> articles = new ConcurrentHashMap<>(); |
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.
HashMap 대신 ConcurrentHashMap을 사용하신 이유는 무엇인가요?
This reverts commit 1a8ff9d7180e13b8b5e41528f4b28c92fff5fa29.
DHkimgit
left a comment
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.
과제하시느라 수고하셨습니다.
| @Autowired | ||
| private JdbcTemplate jdbcTemplate; |
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.
사용하지 않는 객체는 제거해주세요. 인텔리제이에서 제거 후 CTRL + ALT + O 를 누르면 사용하지 않는 임포트문이 한번에 제거됩니다.
| public ResponseEntity<ArticleDTO> postArticle(@RequestBody ArticleDTO articleDTO) { | ||
| ArticleDTO article = articleService.postArticle(articleDTO); | ||
| return ResponseEntity.status(HttpStatus.CREATED).body(article); | ||
| } |
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.
request dto와 response dto를 분리하는 것도 고려해보세요.
|
|
||
| public ArticleDTO articlesId(@PathVariable() Long id) { | ||
| ArticleDTO articles = jdbcTemplate.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.
articlesId 메서드 이름이 모호합니다. 이 메서드가 무슨 역할을 하는지 예측할 수 있도록 동사-명사의 형태(getArticles)로 지어주세요.
|
|
||
| Number key = keyHolder.getKey(); | ||
| articleDTO.setId(key.longValue()); | ||
|
|
||
| articleDTO.setDate(LocalDateTime.now()); | ||
| articleDTO.setRevisedDate(LocalDateTime.now()); | ||
|
|
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.
dto와 도메인 객체의 역할을 혼동하고 계시는 것 같아요. 두가지가 어떤 차이가 있는지 찾아보세요.
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.
아직 도메인에 대한 이해가 부족한 것 같습니다.
DTO는 전달만을 담당하고 도메인은 로직의 중심이며 DB와 매핑된다는 이론적인 부분은 조사했습니다.
이후 더 자세히 조사하여 보고서에 정리하도록 하겠습니다
혹시 해당 코드에선 DB에 입력하는 부분을 따로 빼면 그 부분이 도메인이 되는걸까요..?
|
|
||
| public class MemberDTO { | ||
| private Long ID; | ||
| private String name; | ||
| private String email; | ||
| private String password; |
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.
dto는 보통 불변 객체로 생성합니다. 자바에서는 14 버전부터 불변 객체를 생성할 수 있는 record 가 추가되었습니다.
실습 과제 수행과 함께 DTO, Service, Controller 형식으로 고쳐봤습니다
잘못 수정하거나 형식을 맞추지 못한 부분에 대하여 자세히 알려주세요