【问题标题】:Spring Data Rest: Expose new endpoints for Repository that extends Revision RepositorySpring Data Rest:为扩展 Revision Repository 的 Repository 公开新端点
【发布时间】:2014-11-13 13:17:32
【问题描述】:

我想为我的存储库公开新的端点,它也扩展了 RevisionRepository。

@RepositoryRestResource(collectionResourceRel = "persons", itemResourceRel = "person", path = "persons")
public interface PersonRepository extends PagingAndSortingRepository<PersonEntity, Long>, RevisionRepository<PersonEntity, Long, Integer> {

    Revision<Integer, PersonEntity> findLastChangeRevision(@Param("id") Long id);

    Revisions<Integer, PersonEntity> findRevisions(@Param("id") Long id);

    Page<Revision<Integer, PersonEntity>> findRevisions(@Param("id") Long id, Pageable pageable);

    PersonEntity findByName(@Param("name") String name);
}

我现在的问题是,这些新方法没有公开为 url(findLastChangeRevisionfindRevisions),只有findByName 在搜索 url 下。我目前对实际的 url 形式不是很特别,只要它有效。

我现在知道的唯一选择是

  1. 分离修订存储库
  2. 创建一个映射到“/”的新控制器,以替换 Spring Data Rest 创建的控制器,并手动添加所有存储库链接。我的问题之一是我的链接将被硬编码(与链接到控制器时不同),并且路径将是相对的 - 不一定是坏的,但会使一切不一致。
  3. 添加指向“/”的链接以映射到修订存储库

我对上面的选项有很多保留意见。我不确定如何继续。

【问题讨论】:

  • 我也对这个问题的答案感兴趣。我遇到了一个类似的问题,我想扩展 CrudRepository 的 API

标签: java spring spring-data spring-data-rest hibernate-envers


【解决方案1】:

您的方法名称有误。 Repository 类中的查找方法应该是 findByxxxxxx 而不是 findxxxxx

这似乎是您的代码的问题。

@RepositoryRestResource(collectionResourceRel = "persons", itemResourceRel = "person", path = "persons")
public interface PersonRepository extends PagingAndSortingRepository<PersonEntity, Long>, RevisionRepository<PersonEntity, Long, Integer> {

    Revision<Integer, PersonEntity> findByLastChangeRevision(@Param("id") Long id);

    Revisions<Integer, PersonEntity> findByRevisions(@Param("id") Long id);

    Page<Revision<Integer, PersonEntity>> findByRevisions(@Param("id") Long id, Pageable pageable);

    PersonEntity findByName(@Param("name") String name);
}

【讨论】:

  • 我认为问题在于findLastChangeRevisionfindRevisionsfindRevisions是RevisionRepository暴露的方法
  • 你需要添加一个自定义控制器动作来暴露环境
猜你喜欢
  • 2023-03-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-31
  • 2014-11-27
  • 2016-07-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多