-
Notifications
You must be signed in to change notification settings - Fork 2
hw3-2 #1
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
SANGHEEJEONG
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.
우왕 전체적으로 내 코드랑 비슷한 것 같아
| private String content; | ||
|
|
||
| private int commentCount; | ||
|
|
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.
createdAt은 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에 넣으니까 파라미터로 입력을 받지 않아서 null로 반환하길래 빼긴 했는데
엔티티에서 Dto로 변환할때 setPostedAt을 하는 방법도 있었군,,
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.
아주 좋아용~~ 이거에 대해서는 오늘 알려줄게용~~
|
|
||
| List<Post> findAllByOrderByPostedAtDesc(); | ||
|
|
||
| List<Post> findAllByUserId(Long userId); |
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가 이렇게 똑똑한 줄 몰랐네
JPA에서는 경로를 명확히 지정하는 게 안전하지만, 지금처럼 연관 관계가 명확하게 설정되어 있다면 findAllByUsername처럼 짧은 메서드명으로도 작동할 수 있다. 하지만 현재 돌아가고 있으면 괜찮지만, 다른 팀원이나 미래의 개발자가 코드를 이해하기 쉽게 명시적으로 작성하는 것이 권장된다.
나는 findAllByUse_Username으로 쿼리 날리려고 메서드명 작성했는데 찾아보니까 연관 관계가 매핑되어 있으면 줄여써도 가능하구낭
|
|
||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/posts") |
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.
@RequestMapping("/posts/comments")
이렇게 써도 될 듯
(댓글을 한 개라도 더 달려는 노력..)
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.
아하 엔드포인트 그냥 받아적다 보니 똑같다는걸 인지를 못했네..
No description provided.