Hibernate 分离标准
我有一个 DetachedCriteria,用于根据名称字段搜索表。 我想让搜索不区分大小写,并且想知道是否有一种方法可以在不使用 HQL 的情况下做到这一点。 :
private void searchByFullName(DetachedCriteria criteria, String searchCriteria) {
criteria.add(Restrictions.like("fullName", "%" + searchCriteria.toUpperCase() + "%"));
criteria.addOrder(Order.asc("fullName"));
}
但我想确保它在执行搜索时会忽略大小写,因此它生成的 SQL 应该类似于
SELECT * FROM PEOPLE WHERE ? LIKE toUpper(FULL_NAME);
I have a DetachedCriteria which I am using to search a table based on a name field. I want to make the search case-insensitive, and am wondering if there is a way to do this without using HQL. Something like:
private void searchByFullName(DetachedCriteria criteria, String searchCriteria) {
criteria.add(Restrictions.like("fullName", "%" + searchCriteria.toUpperCase() + "%"));
criteria.addOrder(Order.asc("fullName"));
}
But I want to make sure that it will ignore the case when it does the search, so the SQL it generates should look something like:
SELECT * FROM PEOPLE WHERE ? LIKE toUpper(FULL_NAME);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有类似
http://www.hibernate.org/hib_docs/v3/api/org/hibernate/criterion/Restrictions.html#ilike(java.lang.String,%20java.lang.Object)
there is ilike
http://www.hibernate.org/hib_docs/v3/api/org/hibernate/criterion/Restrictions.html#ilike(java.lang.String,%20java.lang.Object)