Skip to content
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

이상윤(B) - Spring Project with JPA and MySQL Database using docker-compose #5

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

leesy010504
Copy link

1. MySQL Connection

image

2. PostMan

1-1. Add Student
image

1-2. Get Student
image

1-3. Delete Student
image

2-1. Add Course
image

2-2. Get Course
image

2-3. Delete Course
image

3-1. Add Enrollment
image

3-2. Get all Students in Course
image

@leesy010504
Copy link
Author

노션은 도커 컴포즈 보느라 분량조절을 실패했습니다.. 죄송합니다..

Copy link
Contributor

@coke98 coke98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다! 도커 통해서 DB 연동해주신점이 좋네요 JpaRepository를 상속받아 레포지토리 인터페이스를 구현하는 방법으로 한번 짜보시면 좋을 것 같아요.

this.courseService = courseService;
}

@PostMapping("/addCourse")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rest api를 쓰게 된다면, url 접근시 / 만으로도 의미가 완성되지 않을까 싶어요.

Course course = new Course();
course.setCourse_name(form.course_name());
course.setInstructor(form.instructor());
course.setScore(form.score());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setter를 쓰는 방법보다는 생성자를 통해 생성시에만 초기화할 수 있도록 하는것이 좋습니다

@RestController
@RequestMapping("/enrollment")
public class EnrollmentController {
EnrollmentService enrollmentService;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

줄바꿈과 같은 컨벤션도 사소하다고 해도 잘 지킬 수 있도록 습관화하면 좋아요

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

필드 선언할때는 접근제어자 꼭 붙여주세요

private Long course_id;

@Column(name = "course_name")
private String course_name;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name이라는 속성을 통해 이미 DB의 컬럼명을 지정했다면, 자바에서는 컬럼명은 다르게 작성해도 괜찮아요. 자바에서는 컨벤션인 카멜 케이스로 변경하는게 좋을 것 같습니다.

private String instructor;

@Column
private int Score;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

대소문자 같은 컨벤션은 인텔리제이에서 알려줄거라 밑줄 뜨면 한번씩 확인해보세요

return course_id;
}

public void setCourse_id(Long course_id) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setter를 최소화 할 방법은 없을까요? 사용을 최소한으로 둬야하는 이유는 무엇일까요? 고민해보시면 좋을 것 같습니다.

import java.util.List;
import java.util.Optional;

public interface CourseRepository {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JpaRepository를 상속 받기만 하면 어렵게 인터페이스를 구현하실 필요가 없어요. 인터페이스에 선언된 네이밍에 따라 런타임시 자동으로 구현되는 점을 이용해보시길 바랍니다!


import java.util.List;

@Transactional
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

서비스 전체에 붙이는 방법도 있지만 메서드 단위로 붙이고, 트랜잭션 속성(readOnly)을 다르게 줄 수 있도록도 해볼 수 있을 것 같아요.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants