-
Notifications
You must be signed in to change notification settings - Fork 8
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
이지정(M) Spring JPA and H2 Datebase #8
base: main
Are you sure you want to change the base?
Conversation
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 setEnrollments(List<Enrollment> enrollments) { | ||
this.enrollments = enrollments; | ||
} | ||
|
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.
의미없는 개행..! 은 지우는걸 추천드립니다요!
|
||
@ManyToOne | ||
@JoinColumn(name="course_id") | ||
@JsonBackReference |
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.
@JsonBackReference 를 사용하신 이유가 있을실까요?
|
||
@Repository | ||
public interface EnrollmentRepository extends JpaRepository<Enrollment, Integer> { | ||
List<Enrollment> findByStudentStudentId(@Param("studentId") int studentId); |
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.
여기서 @param은 무슨 의미인가요?
|
||
public Enrollment addEnrollment(int studentId, int courseId){ | ||
Student student = studentRepository.findById(studentId).orElseThrow(()->new NoSuchElementException()); | ||
Course course = courseRepository.findById(courseId).orElseThrow(()->new NoSuchElementException()); |
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.
new NoSuchElementException() 은 에러 발생시 어떤 결과를 어디에 보여줄까요?
private String email; | ||
public Student() {} | ||
|
||
@OneToMany(mappedBy = "student") |
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.
(FetchType.LAZY FetchType.EAGER )패치 타입에 대해 알아보시면 좋을 것 같아요!
return studentService.getEnrollments(studentId); | ||
} | ||
|
||
@PostMapping("/{studentId}/{courseId}") |
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.
POST 요청이라면 파라미터 말구 body 값으로 전달하는게 어떨까요?!
데이터베이스 확인
데이터베이스 확인