spring-data-rest - 搜索 API EntityRepresentationModel 未找到

标签 spring-data-rest

我正在尝试创建自定义搜索 API。

@RepositoryRestResource( collectionResourceRel = "products", path = "products" )
public interface ProductFamilyRepository extends JpaRepository<ProductFamily, UUID> {

   @RestResource( path = "pages", rel = "pages" )
   ProductFamily findByPageId( @Param( "pageId" ) String pageId );

执行 http://localhost:8080/products/search/pages?pageId=p33

org.springframework.data.rest.webmvc.ResourceNotFoundException: EntityRepresentationModel not found!
    at org.springframework.data.rest.webmvc.RepositorySearchController.lambda$toModel$2(RepositorySearchController.java:219)
    at java.base/java.util.Optional.orElseThrow(Optional.java:401)
    at org.springframework.data.rest.webmvc.RepositorySearchController.toModel(RepositorySearchController.java:219)
    at org.springframework.data.rest.webmvc.RepositorySearchController.executeSearch(RepositorySearchController.java:185)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    
    

我做错了什么?

最佳答案

问题在于返回类型。它必须是 List<ProductFamily>

关于spring-data-rest - 搜索 API EntityRepresentationModel 未找到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62570321/

相关文章:

java - FileNotFoundException 尝试从 Spring RepositoryRestController 下载文件

jackson - Feign 和 HAL/资源

spring - 是否可以将 Spring Data Rest 配置为使用 id 作为引用而不是 URI?

java - 序列化时如何创建虚拟 JSON 属性?

client - 为 Spring 数据休息服务生成客户端库

java - Spring Data Rest执行查询但返回500内部服务器错误

java - 使用 Spring Data Rest 时公开所有 ID

java - 如何向需要查询实体以执行验证的 JPA 实体添加验证

spring-security - 如何仅获取 GraphRepository 中经过身份验证的用户拥有的数据

spring - Cascade 与 Spring Data REST 保持一致