-
Notifications
You must be signed in to change notification settings - Fork 14
권세빈 1주차 과제 #10
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?
권세빈 1주차 과제 #10
Conversation
sebeeeen
commented
Oct 2, 2024
@Column(name = "School_id") | ||
private Long id; | ||
|
||
@Column(name = "School_name") | ||
private String schoolName; | ||
|
||
@Column(name = "Total_students") | ||
private int totalStudents; | ||
|
||
@Column(name = "Average_grade") | ||
private double averageGrade; |
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.
잘 작성해주셨습니다!
틀린 것은 아니지만! 관례상 자주 사용되는 패턴이 있습니다.
MySQL에서는 Column 이름을 snake_case로 작성하는 것이 일반적입니다.
실제로도 @Column(name = ~)
를 생략하게 되면, 이를 snake_case로 변경하여 DB에 생성합니다.
그리고 table명_id 구조로 PK를 작성하는 편이기도 합니다.
따라서 아래처럼 써보시는 것이 어떠할까 싶네용
@Column(name = "School_id") | |
private Long id; | |
@Column(name = "School_name") | |
private String schoolName; | |
@Column(name = "Total_students") | |
private int totalStudents; | |
@Column(name = "Average_grade") | |
private double averageGrade; | |
@Column(name = "school_id") | |
private Long id; | |
@Column(name = "school_name") | |
private String schoolName; | |
@Column(name = "total_students") | |
private int totalStudents; | |
@Column(name = "average_grade") | |
private double averageGrade; |
@DisplayName("SchoolName과 TotalStudent를 이용한 찾기") | ||
@Test | ||
void testFindBySchoolNameAndTotalStudents() { | ||
// Given | ||
School school1 = School.builder() | ||
.schoolName("아주대학교") | ||
.totalStudents(13884) | ||
.averageGrade(4.3) | ||
.build(); | ||
School school2 = School.builder() | ||
.schoolName("서울대학교") | ||
.totalStudents(35000) | ||
.averageGrade(4.0) | ||
.build(); | ||
schoolRepository.saveAll(List.of(school1, school2)); | ||
|
||
// When | ||
School result1 = schoolRepository.findBySchoolNameAndTotalStudents("아주대학교", 13884); | ||
School result2 = schoolRepository.findBySchoolNameAndTotalStudents("서울대학교", 35000); | ||
|
||
// Then. | ||
Assertions.assertThat(result1).isNotNull(); | ||
Assertions.assertThat(result2.getSchoolName()).isEqualTo("서울대학교"); | ||
Assertions.assertThat(result2.getTotalStudents()).isEqualTo(35000); |
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.
너무 깔끔합니다. LGTM