Java 带有多个 in 运算符的 crudrepository findBy 方法签名?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32796419/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
crudrepository findBy method signature with multiple in operators?
提问by Venkata Rama Raju
I have an Entity Class like this:
我有一个这样的实体类:
@Entity
@Table(name = "EMAIL")
class Email{
@Id
@Column(name = "Id")
Long id;
@Column(name = "EMAIL_ID")
String emailId;
@Column(name = "PIN_CODE")
String pincode;
}
How to write findBy
method for the below query using crudrepository spring data jpa?
如何findBy
使用 crudrepository spring 数据 jpa 为以下查询编写方法?
select email_id,name from email_details where eamil_id in('[email protected]','[email protected]') and pin_code in('633677','733877')
I am expecting the spring data jpa method like the below but how to construct it?
我期待像下面这样的 spring 数据 jpa 方法,但如何构建它?
List<Email> findBy.....(List<String> emails, List<String> pinCodes);
I want to get list of Emails in a single database hit.
我想在单个数据库命中中获取电子邮件列表。
采纳答案by Tunaki
The following signature will do:
以下签名将执行以下操作:
List<Email> findByEmailIdInAndPincodeIn(List<String> emails, List<String> pinCodes);
Spring Data JPA supports a large number of keywords to build a query. IN
and AND
are among them.
Spring Data JPA 支持大量关键字来构建查询。IN
并且AND
在其中。
回答by Manas Ranjan Mahapatra
Try this:
尝试这个:
@Query("select c from Course c where c.course_id=?1 AND c.module_id IN (?2)");
List<Course> findByCourseIdAndModuleIdIn(Long courseId, List<Long> moduleIds);
OR this:
或这个:
List<Course> findByCourseIdAndModuleIdIn(Long courseId, List<Long> moduleIds);
Spring Data JPA supports a large number of keywords to build a query. IN and AND are among them.
Spring Data JPA 支持大量关键字来构建查询。IN 和 AND 就在其中。