首页 > 解决方案 > 可以在 JPA 方法中使用的多个 In 子句

问题描述

我们可以使用两个 In 子句,并且两者都将在 JPA 方法中获取整数列表。例如:findByGroupIdAndUserId(列出 groupIdList,列出 userIdList)

标签: spring-data-jpa

解决方案


Spring 数据尚不支持带有 IN 子句的多列。

您可以使用@Query 注释进行自定义查询,如下所示:

@Query( "select o from MyObject o where groupId in :gids and userId in :uids" ) 
List findByIds(@Param("gids") List groupIdList, @Param("uids") List userIdList);

推荐阅读