-
Notifications
You must be signed in to change notification settings - Fork 13
문소현 1주차 과제 #2
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주차 과제 #2
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package doit.jpastudy2.Library; | ||
|
|
||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.GeneratedValue; | ||
| import jakarta.persistence.GenerationType; | ||
| import jakarta.persistence.Id; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Entity | ||
| @Getter | ||
| @NoArgsConstructor | ||
| public class Book { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.AUTO) | ||
| private Long bookId; | ||
| private String title; | ||
| private String author; | ||
| private String publisher; | ||
| private String isbn; | ||
| private char available; | ||
|
|
||
| @Builder | ||
| public Book(String title, String author, String publisher, String isbn, char available) { | ||
| this.title = title; | ||
| this.author = author; | ||
| this.publisher = publisher; | ||
| this.isbn = isbn; | ||
| this.available = available; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package doit.jpastudy2.Library; | ||
|
|
||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.GeneratedValue; | ||
| import jakarta.persistence.GenerationType; | ||
| import jakarta.persistence.Id; | ||
| import jakarta.validation.constraints.Email; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| import java.time.LocalDate; | ||
|
|
||
| @Entity | ||
| @Getter | ||
| @NoArgsConstructor | ||
| public class Member { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.AUTO) | ||
| private Long memberId; | ||
| private String name; | ||
| private String email; | ||
|
Comment on lines
+23
to
+24
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 유효성 체크 좋네용 |
||
| private String phone; | ||
| private LocalDate joinDate; | ||
| private Long borrow; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 해당 필드는 borrow Table에 대해서 연관 관계를 나타내기 위해서 추가해주신 부분일까요?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. borrow는 빌린 책이 몇 권인지 나타내는 필드입니다..!
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 앗! 위에 테이블에 적혀있었군요ㅋㅋ.. 고생하셨습니다!! |
||
|
|
||
| @Builder | ||
| public Member(String name, String email, String phone, LocalDate joinDate, Long borrow) { | ||
| this.name = name; | ||
| this.email = email; | ||
| this.phone = phone; | ||
| this.joinDate = joinDate; | ||
| this.borrow = borrow; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package doit.jpastudy2.Library.repository; | ||
|
|
||
| import doit.jpastudy2.Library.Book; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| public interface BookRepository extends JpaRepository<Book, Long> { | ||
|
|
||
| public Book findByTitleAndAuthor(String title, String author); | ||
| public Book findByIsbn(String isbn); | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package doit.jpastudy2.Library.repository; | ||
|
|
||
| import doit.jpastudy2.Library.Member; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| public interface MemberRepository extends JpaRepository<Member, Long> { | ||
|
|
||
| public Member findByName(String name); | ||
| public Member findByEmail(String email); | ||
| public Member findByPhone(String phone); | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,32 @@ | ||||||||||||||
| package doit.jpastudy2.Library.repository; | ||||||||||||||
|
|
||||||||||||||
| import doit.jpastudy2.Library.Book; | ||||||||||||||
| import org.junit.jupiter.api.Test; | ||||||||||||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||||||||||||
| import org.springframework.boot.test.context.SpringBootTest; | ||||||||||||||
| import org.springframework.transaction.annotation.Transactional; | ||||||||||||||
|
|
||||||||||||||
| @Transactional | ||||||||||||||
| @SpringBootTest | ||||||||||||||
| class BookRepositoryTest { | ||||||||||||||
|
|
||||||||||||||
| @Autowired | ||||||||||||||
| BookRepository bookRepository; | ||||||||||||||
|
|
||||||||||||||
| @Test | ||||||||||||||
| void test(){ | ||||||||||||||
| Book book = Book.builder() | ||||||||||||||
| .title("모순") | ||||||||||||||
| .author("양귀자") | ||||||||||||||
| .isbn("9788998441012") | ||||||||||||||
| .publisher("쓰다") | ||||||||||||||
| .build(); | ||||||||||||||
|
|
||||||||||||||
| bookRepository.save(book); | ||||||||||||||
|
|
||||||||||||||
| Book book1 = bookRepository.findByTitleAndAuthor("모순","양귀자"); | ||||||||||||||
|
|
||||||||||||||
| System.out.println("Member Id = " + book1.getBookId()); | ||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
종종 직접 값에 대해 print하는 것도 눈으로 확인하고 더욱 확신이 가고 좋습니다. |
||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| } | ||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package doit.jpastudy2.Library.repository; | ||
|
|
||
| import doit.jpastudy2.Library.Member; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.test.context.SpringBootTest; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.time.LocalDateTime; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| @Transactional | ||
| @SpringBootTest | ||
| class MemberRepositoryTest { | ||
|
|
||
| @Autowired | ||
| MemberRepository memberRepository; | ||
|
|
||
| @Test | ||
| void test(){ | ||
| Member member = Member.builder() | ||
| .name("문소현") | ||
| .email("sohyun22@ajou.ac.kr") | ||
| .phone("01012345678") | ||
| .joinDate(LocalDate.now()) | ||
| .build(); | ||
|
|
||
| memberRepository.save(member); | ||
|
|
||
| Member member1 = memberRepository.findByName("문소현"); | ||
|
|
||
| System.out.println("name = " + member1.getEmail()); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.
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.
우선 char을 다음과 'Y'와 'N'을 표현하기 위해서 디테일한 필드 작성 너무 좋습니다!
이에 대해서 한 가지 코멘트 드릴 것이 있다면..
만약 avaiable의 상태가 Y, N을 제외한 추가적인 상황이 있다면 이는 ENUM의 형태로 처리하는 것이 유지보수면에서 좋을 것 같습니다. 그리고 2가지만으로 분류가 된다면 boolean(MySQL에서는 tinyint)로 처리하는 쪽이 어떨까 생각이 들었습니다.