简体   繁体   English

Spring Data JPA Query - count with in 子句

[英]Spring Data JPA Query - count with in clause

I am trying to implement the following query with spring data JPA with method name resolving.我正在尝试使用带有方法名称解析的 spring data JPA 实现以下查询。

select count(*) from example ex where ex.id = id and ex.status in (1, 2);

I know there's a method in crud repo for count which will go like - countByIdAndStatus(params) but I wasn't sure how can I incorporate "in" clause with this method.我知道在 crud repo 中有一个用于计数的方法,它会像 - countByIdAndStatus(params)但我不确定如何将“in”子句与这个方法结合起来。

Thank you!谢谢!

This is how you can do it:你可以这样做:

long countByIdAndStatusIn(Integer id, List<Type> params);

With @Query :使用@Query

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM