Primary key로 찾을 때는 findById(int값)
그외에 칼럼은 findByName , findByEmail , findByNameAndEmail 등등..
@Autowired
MemberRepository memberRepository;
SELECT 문 예시
Member member = memberRepository.findById(int 값).orElse(null);
= select * from member where member_seq = 값
List<Member> member = memberRepository.findAll();
= select * from member (만약 member안에 Play play 같은 객체가 존재하면 play도 조인해서 가져옴)
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
DELETE 문 예시
memberRepository.delete(member) // 멤버 seq에 일치하는 거 행 삭제
= delete from member where member_seq = seq값
memberRepository.deleteById(int값) //int값에 맞는 seq를 찾아서 행 삭제
= delete from member where member_seq = int 값
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
INSERT문 예시
Member member = new Member();
member.setId~
member.setName~
memberRepository.save(member);
= insert into member (id, name) values~
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
UPDATE문 예시
Member member =memberRepository.findById(int값).orElse(null);
member.setName~
memberRepository.save(member);
= update member set name = ? where member_seq = int값
Member 에 seq값이 테이블에 존재하면 update문을 수행하고,
seq가 테이블에 없으면 insert문이 수행된다.