postgresql JPA findBy 字段忽略大小写

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

JPA findBy field ignore case

javaspringpostgresqlspring-data-jpadao

提问by Daria Bulanova

How do I make findByIn search using IgnoreCase of <Field>? I tried to use findByNameIgnoreCaseInand findByNameInIgnoreCasewith no result. DB is Postgresql.

如何使用 IgnoreCase of 进行 findByIn 搜索<Field>?我试图使用findByNameIgnoreCaseInfindByNameInIgnoreCase没有结果。DB 是 Postgresql。

@Repository
public interface UserRepository {
    List<User> findByNameIgnoreCaseIn(List<String> userNames);
}

采纳答案by Daria Bulanova

As I understood IgnoreCase is not supported with In key, so I changed code this way:

据我了解,In 键不支持 IgnoreCase,因此我以这种方式更改了代码:

@Repository
public interface UserRepository {
    @Query("select user from SysUser user where upper(name) in :userNames")
    List<SysUser> findByNameIgnoreCaseIn(@Param("userNames") List<String> userNames);
}

and previously upper case userNames values.

和以前大写的 userNames 值。

回答by Sumeet Tiwari

Try something like this:

尝试这样的事情:

List<User> findByNameInIgnoreCase(List<String> userNames);