0. 설명

JPA 처리를 담당하는 Repository는 기본적으로 4가지가 있다. T는 Entity의 타입클래스이고 ID는 P.K 값의 Type 이다.

1. Repository<T, ID>

2.CrudRepository<T, ID>

<aside> 💡 CRUD 관련 기능들을 제공

</aside>

public interface CrudRepository<T, ID extends Serializable> 
   extends Repository<T, ID> { 

    <S extends T> S save(S entity); 
    
    Optional<T> findById(ID primaryKey); 
    
    Iterable<T> findAll(); long count(); 

    void delete(T entity); boolean existsById(ID primaryKey); 

    // … more functionality omitted. 

}

3. PagingAndSortingRepository<T, ID>

<aside> 💡 페이징 및 sorting 관련 기능들을 제공

</aside>

public interface PagingAndSortingRepository<T, ID extends Serializable> 
    extends CrudRepository<T, ID> { 

   Iterable<T> findAll(Sort sort); 

   Page<T> findAll(Pageable pageable); 

}

// page size 20으로 된 전체 목록에서 두번째 페이지를 아래아 같이 쉽게 가져올 수 있다. 
PagingAndSortingRepository<User, Long> repository = // … get access to a bean 
Page<User> users = repository.findAll(new PageRequest(1, 20));

4. JpaRepository<T, ID>

<aside> 💡 JPA 특화된 기능들을 제공 (flushing, batch) CrudRepository 및 PagingAndSortingRepository의 모든 기능을 가짐

</aside>

T는 Entity의 타입클래스이고 ID는 P.K 값의 Type 이다.