Spring boot Spring数据休息:通过收集<;实体>;作为查询字符串参数
首先,这与在中解决的问题有关 我的问题是(我相信)和它的延伸。我看到以下行为:Spring boot Spring数据休息:通过收集<;实体>;作为查询字符串参数,spring-boot,spring-data,spring-data-jpa,spring-data-rest,spring-hateoas,Spring Boot,Spring Data,Spring Data Jpa,Spring Data Rest,Spring Hateoas,首先,这与在中解决的问题有关 我的问题是(我相信)和它的延伸。我看到以下行为: 我定义了两个存储库查询,例如 Person findByAccount(@Param("account") Account account)); Collection<Person> findByAccountIn(@Param("accounts") Collection<Account> accounts)); 它将运行查询,但会忽略第一个帐户(http://localhost:808
Person findByAccount(@Param("account") Account account));
Collection<Person> findByAccountIn(@Param("accounts") Collection<Account> accounts));
它将运行查询,但会忽略第一个帐户(http://localhost:8080/accounts/1
)并仅基于第二个(http://localhost:8080/accounts/2
)findbyaccountdin(@Param(“accountIds”)集合accountIds)
可以通过http://localhost:8080/people/search/findByAccountIdIn?accountIds=1,2
。这让我相信,在将URI列表传递到需要相应实体集合的查询方法的方式中可能存在错误
提前感谢您的帮助 尝试重复查询参数,因为大多数服务器会将其解释为列表。这可能不是最漂亮的解决方案,但应该有效
http://localhost:8080/people/search/findByAccountIn?accounts=http://localhost:8080/accounts/1&accounts=http://localhost:8080/accounts/2
我知道这永远是古老的,但我找到了答案。
我会把这个放在这里给任何一个走这条路的人:
列出findByAccountIn(@Param(“accounts”)Account…accounts)代码>
请求如下所示:
http://localhost:8080/people/search/findByAccountIn?accounts=http://localhost:8080/accounts/1&accounts=http://localhost:8080/accounts/2&accounts=http://localhost/accounts/anotheraccountid
谢谢您的及时回复,很遗憾,您的建议不起作用。SpringDataREST似乎不支持这一点(或者至少我没有正确地调用它)。例如,以下内容:http://localhost:8080/people/search/findByAccountIdIn?accountIds=1,2
按预期工作,但http://localhost:8080/people/search/findByAccountIdIn?accountIds=1&accountIds=2
生成一个错误页面(正如您提到的建议一样)嗯,是的,sprint data rest似乎不像大多数服务器。我一直在尝试使用我自己的一个小型SpringDataREST解决方案使它也能工作,但到目前为止没有任何效果。我认为您可能需要创建rest存储库的自定义实现,并根据需要实现端点。看看这篇关于创建自定义方法的教程,如果有什么我会告诉你的,我会继续尝试。谢谢你在我的问题上的投资:)。也许这是一个值得在SO之外报告的问题-似乎如果该功能用于收集,它也应该用于收集感谢该链接中的建议-我注意到一个问题是定制存储库方法不会通过spring data rest自动公开,因此,还有另一个过程在单独的restController上公开该方法,并将其作为/search资源下的链接添加,如果在多个地方进行,这可能会有点费劲。我想在此期间,我将使用存储库方法来获取集合ID,希望这在将来能够得到解决——因为我知道在REST API中,ID应该是URL,很抱歉我在度假时响应太晚。是的,如果你想在多个地方做这件事,可能会很费力。你的权利也许值得在一个春季论坛上提及。祝你的解决方案好运!
http://localhost:8080/people/search/findByAccountIn?accounts=http://localhost:8080/accounts/1&accounts=http://localhost:8080/accounts/2