@@ -174,12 +174,13 @@ public class Test {
174174 public static void main (String [] args ) {
175175 // -----------------------------------example-----------------------------------
176176 // 表Example.Criteria增加了工厂方法example()支持,使用后可链式构建查询条件使用example()返回Example对象
177- TbExample ex = new TbExample ()
178- .createCriteria()
179- .andField1EqualTo(1 )
180- .andField2EqualTo(" xxx" )
181- .example();
182- this . tbMapper. selectByExample(ex);
177+ this . tbMapper. selectByExample(
178+ new TbExample ()
179+ .createCriteria()
180+ .andField1EqualTo(1 )
181+ .andField2EqualTo(" xxx" )
182+ .example()
183+ );
183184
184185 // -----------------------------------andIf-----------------------------------
185186 // Criteria增强了链式调用,现在一些按条件增加的查询条件不会打乱链式调用了
@@ -199,23 +200,23 @@ public class Test {
199200 // new
200201 this . tbMapper. selectByExample(
201202 new TbExample ()
202- .createCriteria()
203- .andField1EqualTo(1 )
204- .andField2EqualTo(" xxx" )
205- // 如果随机数大于0.5,附加Field3查询条件
206- .andIf(Math . random() > 0.5 , new TbExample .Criteria .ICriteriaAdd () {
207- @Override
208- public TbExample .Criteria add (TbExample .Criteria add ) {
209- return add. andField3EqualTo(2 )
210- .andField4EqualTo(new Date ());
211- }
212- })
213- // 当然最简洁的写法是采用java8的Lambda表达式,当然你的项目是Java8+
214- .andIf(Math . random() > 0.5 , add - > add
215- .andField3EqualTo(2 )
216- .andField4EqualTo(new Date ())
217- )
218- .example()
203+ .createCriteria()
204+ .andField1EqualTo(1 )
205+ .andField2EqualTo(" xxx" )
206+ // 如果随机数大于0.5,附加Field3查询条件
207+ .andIf(Math . random() > 0.5 , new TbExample .Criteria .ICriteriaAdd () {
208+ @Override
209+ public TbExample .Criteria add (TbExample .Criteria add ) {
210+ return add. andField3EqualTo(2 )
211+ .andField4EqualTo(new Date ());
212+ }
213+ })
214+ // 当然最简洁的写法是采用java8的Lambda表达式,当然你的项目是Java8+
215+ .andIf(Math . random() > 0.5 , add - > add
216+ .andField3EqualTo(2 )
217+ .andField4EqualTo(new Date ())
218+ )
219+ .example()
219220 );
220221
221222 // -----------------------------------orderBy-----------------------------------
0 commit comments