Spring Data JPA Query - 使用in子句计数

Kal*_*kar 2 spring spring-data-jpa

我试图用Spring数据JPA实现以下查询,方法名称解析.

select count(*) from example ex where ex.id = id and ex.status in (1, 2);
Run Code Online (Sandbox Code Playgroud)

我知道crud repo中有一个方法可以计算 - countByIdAndStatus(params)但我不知道如何将"in"子句与此方法结合起来.

谢谢!

Bra*_*zic 7

这是你如何做到的:

long countByIdAndStatusIn(Integer id, List<Type> params);
Run Code Online (Sandbox Code Playgroud)

@Query:

@Query("select count(*) from Example ex where ex.id = ?1 and ex.status in (?2)")
long countByIdAndStatus(Integer id, List<Type> params);
Run Code Online (Sandbox Code Playgroud)