[英]What is difference between CrudRepository and JpaRepository interfaces in Spring Data JPA?
[英]In Spring Boot what is the difference between CrudRepository and JpaRepository in extending a Java repository interface
在 spring 中構建存儲庫時,在我的存儲庫界面中,我使用以下方法對其進行了擴展
extends CrudRepository<EntityName, EntityType> 其中 EntityName 是我的實體的名稱 Class 並且 EntityType 設置為默認類型 Long 請參閱下面的示例代碼
@Repository
public interface RoomRepository extends CrudRepository<Room, Long> {
}
但是我注意到了 JpaRepository 的使用,請參見下面的示例
public interface RoomRepository extends JpaRepository<Room, UUID>{
public Boolean existsRoom(String roomNumber);
}
JpaRepository 擴展了 PagingAndSortingRepository,后者又擴展了 CrudRepository。
因為上面提到的inheritance,所以JpaRepository會具備CrudRepository和PagingAndSortingRepository的所有功能。
所以如果你不需要repository有JpaRepository和PagingAndSortingRepository提供的功能,就用CrudRepository。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.