在Spring CrudRepository中,我们是否支持字段的"IN子句“?如下图所示?
findByInventoryIds(List<Long> inventoryIdList)
如果没有这样的支持,可以考虑哪些优雅的选项?为每个id触发查询可能不是最优的。
发布于 2013-09-25 12:42:07
findByInventoryIdIn(List<Long> inventoryIdList)
应该可以做到这一点。
HTTP请求参数格式如下所示:
Yes ?id=1,2,3
No ?id=1&id=2&id=3
JPA仓库关键字的完整列表可以在current documentation listing中找到。它表明IsIn
是等价的--如果你喜欢用动词表示可读性的话--而且它还支持NotIn
和IsNotIn
。
发布于 2013-09-25 00:47:17
对于Spring中的任何方法,您应该能够自己指定@ CrudRepository。像这样的东西应该是有效的:
@Query( "select o from MyObject o where inventoryId in :ids" )
List<MyObject> findByInventoryIds(@Param("ids") List<Long> inventoryIdList);
https://stackoverflow.com/questions/18987292
复制相似问题