问题
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