简体   繁体   English

Spring Data Rest:为扩展Revision Repository的Repository公开新的端点

[英]Spring Data Rest: Expose new endpoints for Repository that extends Revision Repository

I would like to expose new endpoints for my repository which also extends RevisionRepository. 我想为我的存储库公开新的端点,这也扩展了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);
}

My issue right now, is that these new methods are not exposed as urls ( findLastChangeRevision , findRevisions ) and only findByName is under the search url. 我现在的问题是,这些新方法没有公开为url( findLastChangeRevisionfindRevisions ),只有findByName位于搜索网址下。 I am currently not very particular with regards to the actual url form, as long as it works. 我目前对于实际的网址形式并不是特别关注,只要它有效。

The only option I know right now is to 我现在知道的唯一选择是

  1. Separate the revision repositories 分离修订存储库
  2. Create a new controller that maps to "/", to replace the one created by Spring Data Rest, and add all the repository links manually. 创建一个映射到“/”的新控制器,以替换Spring Data Rest创建的控制器,并手动添加所有存储库链接。 One of my issues here is that my links will be hardcoded (unlike when linking to Controllers), and the paths will be relative-- not necessarily bad, but will make everything inconsistent. 我的一个问题是我的链接将被硬编码(与链接到控制器时不同),路径将是相对的 - 不一定是坏的,但会使一切都不一致。
  3. Add links to "/" that maps to the revision repositories 添加映射到修订存储库的“/”链接

I have a lot of reservations with my option above. 我对上面的选项有很多保留意见。 I am not sure how to proceed. 我不知道该怎么办。

You have made a mistake in your method names. 你在方法名称中犯了一个错误。 Find methods in the Repository class should be findByxxxxxx not findxxxxx 在Repository类中查找方法应该是findByxxxxxx而不是findxxxxx

That seems to be the problem with your code. 这似乎是您的代码的问题。

@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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring Data Rest和Spring Data Envers:如何为扩展Revision Repository的Repository公开REST API - Spring Data Rest & Spring Data Envers: How to expose REST API for Repository that extends Revision Repository 如何使用Spring数据REST公开自定义DTO crud存储库? - How to expose custom DTO crud repository with Spring data REST? 自定义Spring Data REST以仅公开存储库中的选定方法 - Customize Spring Data REST to expose only selected methods from Repository Spring Data Rest Repository 不会公开删除 - Spring Data Rest Repository won't expose delete Spring Data Rest-存储库继承创建奇怪的搜索端点 - Spring Data Rest - Repository inheritance creates strange search endpoints 当 Spring 数据存储库扩展自定义存储库时出现 BeanCreationException - BeanCreationException when Spring Data Repository extends Custom Repository RestRepositoryController 隐藏 REST 存储库端点 - RestRepositoryController hide REST repository endpoints Spring JPA Data Repository无法为扩展CrudRepository的接口创建bean - Spring JPA Data Repository failed to create bean for interface that extends CrudRepository Spring Data REST:覆盖控制器上的存储库方法 - Spring Data REST: Override repository method on the controller 修补到Spring Data REST存储库时发生JsonMappingException - JsonMappingException while PATCHing to a Spring Data REST Repository
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM