java - Spring 数据休息 : Expose new endpoints for Repository that extends Revision Repository

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

我想为我的存储库公开新的端点,它也扩展了 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 形式不是很特别,只要它有效即可。

我现在唯一知道的选择是

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

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

最佳答案

您的方法名称有误。 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/

相关文章:

java - 如何使用一个构建文件在 Ant 中构建多个项目?

java - 使用 Spring Kafka 批处理消费者进行非阻塞重试

java - 如何创建Web服务代理?我们可以生成@Endpoints吗?

java - Spring 数据 JPA 自定义存储库,如何应用逻辑

java - 升级到 5.1.39 之后找不到 mysql-connector-java 驱动程序

java - Spring JPA - 枚举中枚举字段的默认值

java - Spring事务内部

java - 使用 Maven 配置文件时出错

java - 使用jpa规范时如何在排序中应用合并表达式

java - spring-data postgres 事务隔离问题