Regular expression with criteria

假装没事ソ 提交于 2019-12-20 03:38:10

问题


I have a table in which certain words or word groups are stored. I want to select entries which start with an uppercase letter, cointain no space and contain only letters. My SQL looks like this:

select word from words where w_id > 100 AND word REGEXP '^[A-Z][A-Za-z]*$' limit 2000;

How do I do the same thing using criteria?


回答1:


Try this:

List words = session.createCriteria(Word.class)
.setProjection(Projections.property("word"))
.add(Restrictions.and(Restrictions.gt("w_id",100), Restrictions.sqlRestriction(word REGEXP '^[A-Z][A-Za-z]*$')))
.setMaxResults(2000).list();


来源:https://stackoverflow.com/questions/25747770/regular-expression-with-criteria

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!