Spring Data JPA 中的 CrudRepository 和 JpaRepository 接口有什么区别? [英] What is difference between CrudRepository and JpaRepository interfaces in Spring Data JPA?

查看:37
本文介绍了Spring Data JPA 中的 CrudRepository 和 JpaRepository 接口有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CrudRepositorySpring Data JPA 中的 rel="noreferrer">JpaRepository 接口?

What is the difference between CrudRepository and JpaRepository interfaces in Spring Data JPA?

当我在网上看到这些示例时,我发现它们可以互换使用.

When I see the examples on the web, I see them there used kind of interchangeably.

它们之间有什么区别?

为什么要使用一个而不是另一个?

Why would you want to use one over the other?

推荐答案

JpaRepository 扩展 PagingAndSortingRepository 反过来又扩展了 CrudRepository.

它们的主要功能是:

由于上面提到的继承,JpaRepository将拥有CrudRepositoryPagingAndSortingRepository的所有功能.因此,如果您不需要存储库具有 JpaRepositoryPagingAndSortingRepository 提供的功能,请使用 CrudRepository.

Because of the inheritance mentioned above, JpaRepository will have all the functions of CrudRepository and PagingAndSortingRepository. So if you don't need the repository to have the functions provided by JpaRepository and PagingAndSortingRepository , use CrudRepository.

这篇关于Spring Data JPA 中的 CrudRepository 和 JpaRepository 接口有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆