【问题标题】:Repository in Spring REST ApplicationSpring REST 应用程序中的存储库
【发布时间】:2020-11-06 22:05:50
【问题描述】:

我有一个简单的问题,当我用谷歌搜索时找不到答案:在构建 Spring REST Web 应用程序时,是否可以使用 @Repository 注释存储库,如下所示:@Repository 公共接口 UserRepository 扩展了 JpaRepository,还是应该在 REST 应用程序中不使用这个注解?

【问题讨论】:

    标签: rest


    【解决方案1】:

    是的,存储库应注释为@Repository。我正在使用它并且它有效:D 我的例子:

    @Repository
    public interface RepositoryNote extends JpaRepository<EntityNote, UUID> {
    
        EntityNote findByUuid(UUID uuid);
    }
    

    关于@Repository的文档:

    Indicates that an annotated class is a "Repository", originally defined by
      Domain-Driven Design (Evans, 2003) as "a mechanism for encapsulating storage,
      retrieval, and search behavior which emulates a collection of objects".
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-01
      • 2017-04-30
      • 2017-08-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多