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
JPA findBy field ignore case
提问by Daria Bulanova
How do I make findByIn search using IgnoreCase of <Field>
?
I tried to use findByNameIgnoreCaseIn
and findByNameInIgnoreCase
with no result.
DB is Postgresql.
如何使用 IgnoreCase of 进行 findByIn 搜索<Field>
?我试图使用findByNameIgnoreCaseIn
并findByNameInIgnoreCase
没有结果。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);