crudrepository findBy方法签名与多个in运算符?


80

我有一个这样的实体类:

@Entity
@Table(name = "EMAIL")
class Email{
    @Id
    @Column(name = "Id")
    Long id;
    @Column(name = "EMAIL_ID")
    String emailId;
    @Column(name = "PIN_CODE")
    String pincode;
}

如何findBy使用crudrepository spring数据jpa编写以下查询的方法?

select email_id,name from email_details where eamil_id in('mike@gmail.com','ram@gmail.com') and pin_code in('633677','733877')

我期望像下面这样的spring data jpa方法,但是如何构造它呢?

List<Email> findBy.....(List<String> emails, List<String> pinCodes);

我想在单个数据库命中中获取电子邮件列表。

Answers:


174

以下签名将起作用:

List<Email> findByEmailIdInAndPincodeIn(List<String> emails, List<String> pinCodes);

Spring Data JPA支持大量关键字来构建查询。INAND在其中


1
9个月的搜索只是为了得到一个简单的答案。感谢你!
Antonio112009
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.