我想为我的存储库公开新的端点,它也扩展了 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(findLastChangeRevision
、findRevisions
),只有 findByName
在搜索网址。我目前对实际的 url 形式不是很特别,只要它有效即可。
我现在唯一知道的选择是
- 分离修订存储库
- 创建一个映射到“/”的新 Controller ,以替换由 Spring Data Rest 创建的 Controller ,并手动添加所有存储库链接。我的问题之一是我的链接将被硬编码(与链接到 Controller 时不同),并且路径是相对的——不一定是坏的,但会使一切不一致。
- 将链接添加到映射到修订存储库的“/”
我对上面的选项有很多保留意见。我不确定如何进行。
最佳答案
您的方法名称有误。 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);
}
关于java - Spring 数据休息 : Expose new endpoints for Repository that extends Revision Repository,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25925538/