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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 13:06:43  来源:igfitidea点击:

crudrepository findBy method signature with multiple in operators?

javaspringspring-dataspring-data-jpa

提问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 findBymethod 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. INand ANDare 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 就在其中。