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

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

问题描述

Spring Data JPA中的 CrudRepository 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. What is the difference between them? Why would you want to use one over the other?

推荐答案

JpaRepository 扩展 PagingAndSortingRepository 反过来扩展 CrudRepository

他们的主要功能是:

  • CrudRepository mainly provides CRUD functions.
  • PagingAndSortingRepository provides methods to do pagination and sorting records.
  • JpaRepository provides some JPA-related methods such as flushing the persistence context and deleting records in a batch.

由于上面提到的继承, JpaRepository 将具有 CrudRepository PagingAndSortingRepository 。因此,如果您不需要存储库具有 JpaRepository PagingAndSortingRepository 提供的功能,请使用 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天全站免登陆