import org.springframework.data.jpa.repository.JpaRepository;
public interface MemberRepository extends JpaRepository<Member, Long> {
}
springframework.data.repository.Repository
를 구현한 클래스는 스캔 대상
MemberRepository
인터페이스가 동작한 이유getClass()
-> class com.sun.proxy.$ProxyXXX
@Repository
애노테이션 생략 가능
JpaRepository
인터페이스: 공통 CRUD 제공save(S)
: 새로운 엔티티는 저장하고 이미 있는 엔티티는 병합한다.delete(T)
: 엔티티 하나를 삭제한다. 내부에서 remove() 호출findById(ID)
: 엔티티 하나를 조회한다. 내부에서find() 호출getOne(ID)
: 엔티티를 프록시로 조회한다.
내부에서 EntityManager.getReference()
호출
findAll(…)
: 모든 엔티티를 조회한다. 정렬(Sort)이나 페이징(Pageable) 조건을 파라미터로 제공할 수 있다.