이상윤(B) - Spring Project with JPA and MySQL Database using docker-compose#5
이상윤(B) - Spring Project with JPA and MySQL Database using docker-compose#5leesy010504 wants to merge 6 commits into
Conversation
|
노션은 도커 컴포즈 보느라 분량조절을 실패했습니다.. 죄송합니다.. |
coke98
left a comment
There was a problem hiding this comment.
고생하셨습니다! 도커 통해서 DB 연동해주신점이 좋네요 JpaRepository를 상속받아 레포지토리 인터페이스를 구현하는 방법으로 한번 짜보시면 좋을 것 같아요.
| this.courseService = courseService; | ||
| } | ||
|
|
||
| @PostMapping("/addCourse") |
There was a problem hiding this comment.
rest api를 쓰게 된다면, url 접근시 / 만으로도 의미가 완성되지 않을까 싶어요.
| Course course = new Course(); | ||
| course.setCourse_name(form.course_name()); | ||
| course.setInstructor(form.instructor()); | ||
| course.setScore(form.score()); |
There was a problem hiding this comment.
setter를 쓰는 방법보다는 생성자를 통해 생성시에만 초기화할 수 있도록 하는것이 좋습니다
| @RestController | ||
| @RequestMapping("/enrollment") | ||
| public class EnrollmentController { | ||
| EnrollmentService enrollmentService; |
There was a problem hiding this comment.
줄바꿈과 같은 컨벤션도 사소하다고 해도 잘 지킬 수 있도록 습관화하면 좋아요
| private Long course_id; | ||
|
|
||
| @Column(name = "course_name") | ||
| private String course_name; |
There was a problem hiding this comment.
name이라는 속성을 통해 이미 DB의 컬럼명을 지정했다면, 자바에서는 컬럼명은 다르게 작성해도 괜찮아요. 자바에서는 컨벤션인 카멜 케이스로 변경하는게 좋을 것 같습니다.
| private String instructor; | ||
|
|
||
| @Column | ||
| private int Score; |
There was a problem hiding this comment.
대소문자 같은 컨벤션은 인텔리제이에서 알려줄거라 밑줄 뜨면 한번씩 확인해보세요
| return course_id; | ||
| } | ||
|
|
||
| public void setCourse_id(Long course_id) { |
There was a problem hiding this comment.
setter를 최소화 할 방법은 없을까요? 사용을 최소한으로 둬야하는 이유는 무엇일까요? 고민해보시면 좋을 것 같습니다.
| import java.util.List; | ||
| import java.util.Optional; | ||
|
|
||
| public interface CourseRepository { |
There was a problem hiding this comment.
JpaRepository를 상속 받기만 하면 어렵게 인터페이스를 구현하실 필요가 없어요. 인터페이스에 선언된 네이밍에 따라 런타임시 자동으로 구현되는 점을 이용해보시길 바랍니다!
|
|
||
| import java.util.List; | ||
|
|
||
| @Transactional |
There was a problem hiding this comment.
서비스 전체에 붙이는 방법도 있지만 메서드 단위로 붙이고, 트랜잭션 속성(readOnly)을 다르게 줄 수 있도록도 해볼 수 있을 것 같아요.
1. MySQL Connection
2. PostMan
1-1. Add Student

1-2. Get Student

1-3. Delete Student

2-1. Add Course

2-2. Get Course

2-3. Delete Course

3-1. Add Enrollment

3-2. Get all Students in Course
