Java 什么是 Spring Data JPA 方法来对多个字段使用 findBy 并对所有字段使用 Containing 子句

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44411022/
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-12 01:32:21  来源:igfitidea点击:

What is the Spring Data JPA method to use findBy for multiple fields and also use Containing clause for all the fields

javaspringdb2repositoryspring-data-jpa

提问by user2632905

I have a class called Profile and its JPA repository ProfileRepo I'm trying to use findBy method to find names using first name or middle name or last name and also using containing clause.

我有一个名为 Profile 的类及其 JPA 存储库 ProfileRepo 我正在尝试使用 findBy 方法来查找使用名字或中间名或姓氏的名称并使用包含子句。

public class Profile{
    private String firstName;
    private String middleName;
    private String lastName;

    //getters and setters
}

Am using the following query in the JPA repository but it is not accepting the method

我在 JPA 存储库中使用以下查询,但它不接受该方法

List<Profile> findByLastNameContainingOrFirstNameContainingOrMiddleNameContainingAllIgnoreCase(String firstName,
        String lastName,String midName);

Kindly help out.

请帮忙。

采纳答案by Cepr0

Try this:

尝试这个:

List<Profile> findByFirstNameIgnoreCaseContainingOrLastNameIgnoreCaseContainingOrMidNameIgnoreCaseContaining(String firstName, String lastName, String midName);

or this:

或这个:

@Query("select p from Profile p where upper(p.firstName) like concat('%', upper(?1), '%') or upper(p.lastName) like concat('%', upper(?2), '%') or upper(p.midName) like concat('%', upper(?3), '%')")
List<Profile> getByNames(String firstName, String lastName, String midName);