我想用MyBatis创建一个查询,它将产生如下内容:
SELECT first_field,second_filed,third_field WHERE first_field > 1 AND (second_field > 0 OR third_field < 0)
我怎么能用Criteria对象构造它?
解决方法
一种方法是到
extend the generated Example classes:
The generated “example” class includes a nested inner class where the actual functionality of the predicates exists. This inner class is always named GeneratedCriteria.
MBG also generates an inner class named Criteria which extends GeneratedCriteria and which you may use for adding your own functions to the example classes. The Criteria class will not be deleted by the Eclipse Java code merger,so you may add to it without fear of losing your changes upon regeneration.
public Criteria multiColumnOrClause(String value1,String value2) { addCriterion("value1 = " + value1 + " OR value2 = " + value2); return this; }