对多个字段使用 findBy 并对所有字段使用包含子句的 Spring Data JPA 方法是什么
我有一个名为 Profile 的类及其 JPA 存储库 ProfileRepo我正在尝试使用 findBy 方法来查找使用名字或中间名或姓氏以及包含子句的名称.
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.
public class Profile{
private String firstName;
private String middleName;
private String lastName;
//getters and setters
}
我在 JPA 存储库中使用以下查询,但它不接受该方法
Am using the following query in the JPA repository but it is not accepting the method
List<Profile> findByLastNameContainingOrFirstNameContainingOrMiddleNameContainingAllIgnoreCase(String firstName,
String lastName,String midName);
请帮忙.
推荐答案
试试这个:
List<Profile> findByFirstNameIgnoreCaseContainingOrLastNameIgnoreCaseContainingOrMidNameIgnoreCaseContaining(String firstName, String lastName, String midName);
或者这个:
@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);
相关文章