springboot整合JPA時會用到的幾個Repository包含以下幾個:
org.springframework.data.repository.Repository<T, ID>
org.springframework.data.repository.CrudRepository<T, ID>
org.springframework.data.repository.PagingAndSortingRepository<T, ID>
org.springframework.data.jpa.repository.JpaRepository<T, ID>
org.springframework.data.repository.query.QueryByExampleExecutor<T>
org.springframework.data.jpa.repository.JpaSpecificationExecutor<T>
其中前4個的繼承關(guān)系,如圖:

image.png
其中CrudRepository主要封裝了有些增刪改查的操作,PagingAndSortingRepository封裝了分頁查詢操作,QueryByExampleExecutor(QBE)分裝了Example查詢,JpaSpecificationExecutor封裝了以Criteria為基礎(chǔ)的查詢。一般情況下,在開發(fā)過程中繼承JpaRepository即可滿足基本需求,該類包含了上述類(除JpaSpecificationExecutor)中的全部操作,如需使用Specification查詢,則需要額外繼承JpaSpecificationExecutor。