问题描述
在Spring CrudRepository中,我们是否支持字段的IN子句?即类似于以下内容?
In Spring CrudRepository, do we have support for "IN clause" for a field? ie something similar to the following?
findByInventoryIds(List<Long> inventoryIdList)
如果没有这样的支持,可以考虑哪些优雅的选择?触发每个id的查询可能不是最佳的。
If such support is not available, what elegant options can be considered? Firing queries for each id may not be optimal.
推荐答案
findByInventoryIdIn(List< Long> inventoryIdList)
应该这样做。
HTTP请求参数格式如下:
The HTTP request parameter format would be like so:
Yes ?id=1,2,3
No ?id=1&id=2&id=3
可以在。它显示 IsIn
是等效的 - 如果您更喜欢动词的可读性 - 并且JPA还支持 NotIn
和 IsNotIn
。
The complete list of JPA repository keywords can be found in the current documentation listing. It shows that IsIn
is equivalent – if you prefer the verb for readability – and that JPA also supports NotIn
and IsNotIn
.
这篇关于Spring CrudRepository findByInventoryIds(List< Long> inventoryIdList) - 相当于IN子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!