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

이지정(M) Spring JPA and H2 Datebase #8

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

Conversation

o-jeong
Copy link

@o-jeong o-jeong commented Jul 13, 2024

  1. 수강 과목 조회
스크린샷 2024-07-14 오전 1 23 33
  1. 수강 과목 추가
스크린샷 2024-07-14 오전 1 26 31

데이터베이스 확인
스크린샷 2024-07-14 오전 1 26 50

  1. 수강 과목 삭제
스크린샷 2024-07-14 오전 1 27 30

데이터베이스 확인
스크린샷 2024-07-14 오전 1 27 41

Copy link
Member

@mjj111 mjj111 left a 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;
}

Copy link
Member

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
Copy link
Member

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);
Copy link
Member

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());
Copy link
Member

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")
Copy link
Member

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}")
Copy link
Member

Choose a reason for hiding this comment

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

POST 요청이라면 파라미터 말구 body 값으로 전달하는게 어떨까요?!

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