【问题标题】:Why The Returned Data Type of findAll Method Are Different Between CrudRepository And JpaRepositiory?为什么 CrudRepository 和 JpaRepository 的 findAll 方法返回的数据类型不同?
【发布时间】:2021-06-06 19:59:55
【问题描述】:

对于 CrudRepository 和 JpaRespository,findAll 方法返回的数据类型是 Iterable 和 List。 JpaRepository 扩展了 PagingAndSortingRepository,后者扩展了 CrudRepository。我想知道为什么返回的数据类型不同。有什么见解吗?

【问题讨论】:

    标签: spring-data-jpa


    【解决方案1】:

    CrudRepositoryspring-data-commons 中定义,所有 Spring Data 模块都使用它。 使用 Iterable 背后的想法是允许商店在方法返回时不实现完整结果。

    JPA 中的查询返回 List 实例,因此没有理由不返回 List 实例。

    实际上,没有任何模块返回非集合Iterable,团队刚刚讨论过我们可能会在不久的将来将返回类型更改为Collection

    【讨论】:

      猜你喜欢
      • 2015-10-31
      • 2018-06-01
      • 2019-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-25
      • 1970-01-01
      • 2021-05-20
      相关资源
      最近更新 更多