【发布时间】:2016-08-12 06:46:13
【问题描述】:
首先,这与 Spring Data Rest: How to search by another object's key? 有关,这似乎在 https://jira.spring.io/browse/DATAREST-502 中得到解决
我的问题是(我相信)和扩展。我看到以下行为:
-
我定义了两个存储库查询,例如
Person findByAccount(@Param("account") Account account)); Collection<Person> findByAccountIn(@Param("accounts") Collection<Account> accounts)); - 两种搜索方法都通过 spring-data-rest 公开。我可以使用
http://localhost:8080/people/search/findByAccount?account=http://localhost:8080/accounts/1等网址访问第一个 -
我可以使用
http://localhost:8080/people/search/findByAccountIn?accounts=http://localhost:8080/accounts/1之类的url 访问第二种方法,但是如果我尝试传入多个帐户,例如http://localhost:8080/people/search/findByAccountIn?accounts=http://localhost:8080/accounts/1,http://localhost:8080/accounts/2,它将运行查询,但忽略第一个帐户 (
http://localhost:8080/accounts/1) 并仅基于第二个帐户 (http://localhost:8080/accounts/2) 进行搜索
通过 REST API 将实体集合传递给存储库参数的正确技术是什么?我发现它适用于单个实体,但不适用于集合。请注意,直接访问 JpaRepository 时,这两种存储库方法都按预期工作。
还要注意,如果集合是某种原始类型,这些查询似乎可以工作,例如,findByAccountIdIn(@Param("accountIds") Collection<Long> accountIds) 可通过http://localhost:8080/people/search/findByAccountIdIn?accountIds=1,2 使用预期功能访问。这让我相信,将 URI 列表传递给需要相应实体集合的查询方法的方式可能是错误的。
提前感谢您的帮助!
【问题讨论】:
标签: spring-boot spring-data spring-data-jpa spring-data-rest spring-hateoas