首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Spring CrudRepository findByInventoryIds(List<Long> inventoryIdList) -等同于IN子句

Spring CrudRepository findByInventoryIds(List<Long> inventoryIdList) -等同于IN子句
EN

Stack Overflow用户
提问于 2013-09-25 00:37:02
回答 2查看 251.6K关注 0票数 221

在Spring CrudRepository中,我们是否支持字段的"IN子句“?如下图所示?

代码语言:javascript
复制
 findByInventoryIds(List<Long> inventoryIdList) 

如果没有这样的支持,可以考虑哪些优雅的选项?为每个id触发查询可能不是最优的。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-09-25 12:42:07

findByInventoryIdIn(List<Long> inventoryIdList)应该可以做到这一点。

HTTP请求参数格式如下所示:

代码语言:javascript
复制
Yes ?id=1,2,3
No  ?id=1&id=2&id=3

JPA仓库关键字的完整列表可以在current documentation listing中找到。它表明IsIn是等价的--如果你喜欢用动词表示可读性的话--而且它还支持NotInIsNotIn

票数 369
EN

Stack Overflow用户

发布于 2013-09-25 00:47:17

对于Spring中的任何方法,您应该能够自己指定@ CrudRepository。像这样的东西应该是有效的:

代码语言:javascript
复制
@Query( "select o from MyObject o where inventoryId in :ids" )
List<MyObject> findByInventoryIds(@Param("ids") List<Long> inventoryIdList);
票数 122
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18987292

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档