不区分大小写等于使用Hibernate标准 [英] Case-insensitive equals using Hibernate Criteria
本文介绍了不区分大小写等于使用Hibernate标准的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我见过Restrictions.ilike('property','%value%'),但想生成如下所示的SQL:lower(property)='value'。任何想法?
I've seen Restrictions.ilike('property', '%value%'), but would like to generate SQL like: lower(property) = 'value'. Any ideas?
我用:
I used:
Restrictions.eq("email", email).ignoreCase()
,因为表达式已被弃用。 SimpleExpression将对该值调用toLowerCase(),所以事先不需要这样做。
since Expression is deprecated. The SimpleExpression will call toLowerCase() on the value, so it is not necessary to do it beforehand.
推荐答案
小心使用ilike,因为它会允许某人输入诸如test%之类的内容并进行匹配。我使用以下内容在一个应用程序中执行不区分大小写的操作:
Be careful of using ilike because it would allow someone to enter things like "test%" and match. I use the following to do a case-insensitive equal in one app:
...
Criteria crit=session.createCriteria(Event.class);
crit.add(Expression.eq("rsvpCode","test1").ignoreCase());
...
这篇关于不区分大小写等于使用Hibernate标准的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文