@@ -232,18 +232,33 @@ public List<Criteria> getOredCriteria() {
232
232
}
233
233
234
234
public void or (Criteria criteria ) {
235
+ criteria .setAndOr ("or" );
235
236
oredCriteria .add (criteria );
236
237
}
237
238
238
239
public Criteria or () {
239
240
Criteria criteria = createCriteriaInternal ();
241
+ criteria .setAndOr ("or" );
242
+ oredCriteria .add (criteria );
243
+ return criteria ;
244
+ }
245
+
246
+ public void and (Criteria criteria ) {
247
+ criteria .setAndOr ("and" );
248
+ oredCriteria .add (criteria );
249
+ }
250
+
251
+ public Criteria and () {
252
+ Criteria criteria = createCriteriaInternal ();
253
+ criteria .setAndOr ("and" );
240
254
oredCriteria .add (criteria );
241
255
return criteria ;
242
256
}
243
257
244
258
public Criteria createCriteria () {
245
259
Criteria criteria = createCriteriaInternal ();
246
260
if (oredCriteria .size () == 0 ) {
261
+ criteria .setAndOr ("and" );
247
262
oredCriteria .add (criteria );
248
263
}
249
264
return criteria ;
@@ -280,6 +295,8 @@ protected abstract static class GeneratedCriteria {
280
295
protected boolean exists ;
281
296
//值是否不能为空
282
297
protected boolean notNull ;
298
+ //连接条件
299
+ protected String andOr ;
283
300
//属性和列对应
284
301
protected Map <String , EntityColumn > propertyMap ;
285
302
@@ -311,6 +328,14 @@ private String property(String property) {
311
328
}
312
329
}
313
330
331
+ public String getAndOr () {
332
+ return andOr ;
333
+ }
334
+
335
+ public void setAndOr (String andOr ) {
336
+ this .andOr = andOr ;
337
+ }
338
+
314
339
public boolean isValid () {
315
340
return criteria .size () > 0 ;
316
341
}
@@ -361,6 +386,44 @@ protected void addCriterion(String condition, Object value1, Object value2, Stri
361
386
criteria .add (new Criterion (condition , value1 , value2 ));
362
387
}
363
388
389
+ protected void addOrCriterion (String condition ) {
390
+ if (condition == null ) {
391
+ throw new MapperException ("Value for condition cannot be null" );
392
+ }
393
+ if (condition .startsWith ("null" )) {
394
+ return ;
395
+ }
396
+ criteria .add (new Criterion (condition , true ));
397
+ }
398
+
399
+ protected void addOrCriterion (String condition , Object value , String property ) {
400
+ if (value == null ) {
401
+ if (notNull ) {
402
+ throw new MapperException ("Value for " + property + " cannot be null" );
403
+ } else {
404
+ return ;
405
+ }
406
+ }
407
+ if (property == null ) {
408
+ return ;
409
+ }
410
+ criteria .add (new Criterion (condition , value , true ));
411
+ }
412
+
413
+ protected void addOrCriterion (String condition , Object value1 , Object value2 , String property ) {
414
+ if (value1 == null || value2 == null ) {
415
+ if (notNull ) {
416
+ throw new MapperException ("Between values for " + property + " cannot be null" );
417
+ } else {
418
+ return ;
419
+ }
420
+ }
421
+ if (property == null ) {
422
+ return ;
423
+ }
424
+ criteria .add (new Criterion (condition , value1 , value2 , true ));
425
+ }
426
+
364
427
public Criteria andIsNull (String property ) {
365
428
addCriterion (column (property ) + " is null" );
366
429
return (Criteria ) this ;
@@ -529,6 +592,145 @@ public Criteria andAllEqualTo(Object param) {
529
592
}
530
593
return (Criteria ) this ;
531
594
}
595
+
596
+ public Criteria orIsNull (String property ) {
597
+ addOrCriterion (column (property ) + " is null" );
598
+ return (Criteria ) this ;
599
+ }
600
+
601
+ public Criteria orIsNotNull (String property ) {
602
+ addOrCriterion (column (property ) + " is not null" );
603
+ return (Criteria ) this ;
604
+ }
605
+
606
+ public Criteria orEqualTo (String property , Object value ) {
607
+ addOrCriterion (column (property ) + " =" , value , property (property ));
608
+ return (Criteria ) this ;
609
+ }
610
+
611
+ public Criteria orNotEqualTo (String property , Object value ) {
612
+ addOrCriterion (column (property ) + " <>" , value , property (property ));
613
+ return (Criteria ) this ;
614
+ }
615
+
616
+ public Criteria orGreaterThan (String property , Object value ) {
617
+ addOrCriterion (column (property ) + " >" , value , property (property ));
618
+ return (Criteria ) this ;
619
+ }
620
+
621
+ public Criteria orGreaterThanOrEqualTo (String property , Object value ) {
622
+ addOrCriterion (column (property ) + " >=" , value , property (property ));
623
+ return (Criteria ) this ;
624
+ }
625
+
626
+ public Criteria orLessThan (String property , Object value ) {
627
+ addOrCriterion (column (property ) + " <" , value , property (property ));
628
+ return (Criteria ) this ;
629
+ }
630
+
631
+ public Criteria orLessThanOrEqualTo (String property , Object value ) {
632
+ addOrCriterion (column (property ) + " <=" , value , property (property ));
633
+ return (Criteria ) this ;
634
+ }
635
+
636
+ public Criteria orIn (String property , Iterable values ) {
637
+ addOrCriterion (column (property ) + " in" , values , property (property ));
638
+ return (Criteria ) this ;
639
+ }
640
+
641
+ public Criteria orNotIn (String property , Iterable values ) {
642
+ addOrCriterion (column (property ) + " not in" , values , property (property ));
643
+ return (Criteria ) this ;
644
+ }
645
+
646
+ public Criteria orBetween (String property , Object value1 , Object value2 ) {
647
+ addOrCriterion (column (property ) + " between" , value1 , value2 , property (property ));
648
+ return (Criteria ) this ;
649
+ }
650
+
651
+ public Criteria orNotBetween (String property , Object value1 , Object value2 ) {
652
+ addOrCriterion (column (property ) + " not between" , value1 , value2 , property (property ));
653
+ return (Criteria ) this ;
654
+ }
655
+
656
+ public Criteria orLike (String property , String value ) {
657
+ addOrCriterion (column (property ) + " like" , value , property (property ));
658
+ return (Criteria ) this ;
659
+ }
660
+
661
+ public Criteria orNotLike (String property , String value ) {
662
+ addOrCriterion (column (property ) + " not like" , value , property (property ));
663
+ return (Criteria ) this ;
664
+ }
665
+
666
+ /**
667
+ * 手写条件
668
+ *
669
+ * @param condition 例如 "length(countryname)<5"
670
+ * @return
671
+ */
672
+ public Criteria orCondition (String condition ) {
673
+ addOrCriterion (condition );
674
+ return (Criteria ) this ;
675
+ }
676
+
677
+ /**
678
+ * 手写左边条件,右边用value值
679
+ *
680
+ * @param condition 例如 "length(countryname)="
681
+ * @param value 例如 5
682
+ * @return
683
+ */
684
+ public Criteria orCondition (String condition , Object value ) {
685
+ criteria .add (new Criterion (condition , value , true ));
686
+ return (Criteria ) this ;
687
+ }
688
+
689
+ /**
690
+ * 将此对象的不为空的字段参数作为相等查询条件
691
+ *
692
+ * @param param 参数对象
693
+ * @author Bob {@link}0haizhu0@gmail.com
694
+ * @Date 2015年7月17日 下午12:48:08
695
+ */
696
+ public Criteria orEqualTo (Object param ) {
697
+ MetaObject metaObject = SystemMetaObject .forObject (param );
698
+ String [] properties = metaObject .getGetterNames ();
699
+ for (String property : properties ) {
700
+ //属性和列对应Map中有此属性
701
+ if (propertyMap .get (property ) != null ) {
702
+ Object value = metaObject .getValue (property );
703
+ //属性值不为空
704
+ if (value != null ) {
705
+ orEqualTo (property , value );
706
+ }
707
+ }
708
+ }
709
+ return (Criteria ) this ;
710
+ }
711
+
712
+ /**
713
+ * 将此对象的所有字段参数作为相等查询条件,如果字段为 null,则为 is null
714
+ *
715
+ * @param param 参数对象
716
+ */
717
+ public Criteria orAllEqualTo (Object param ) {
718
+ MetaObject metaObject = SystemMetaObject .forObject (param );
719
+ String [] properties = metaObject .getGetterNames ();
720
+ for (String property : properties ) {
721
+ //属性和列对应Map中有此属性
722
+ if (propertyMap .get (property ) != null ) {
723
+ Object value = metaObject .getValue (property );
724
+ //属性值不为空
725
+ if (value != null ) {
726
+ orEqualTo (property , value );
727
+ } else {
728
+ orIsNull (property );
729
+ }
730
+ }
731
+ }
732
+ return (Criteria ) this ;
733
+ }
532
734
}
533
735
534
736
public static class Criteria extends GeneratedCriteria {
@@ -545,6 +747,8 @@ public static class Criterion {
545
747
546
748
private Object secondValue ;
547
749
750
+ private String andOr ;
751
+
548
752
private boolean noValue ;
549
753
550
754
private boolean singleValue ;
@@ -556,39 +760,62 @@ public static class Criterion {
556
760
private String typeHandler ;
557
761
558
762
protected Criterion (String condition ) {
763
+ this (condition , false );
764
+ }
765
+
766
+ protected Criterion (String condition , Object value , String typeHandler ) {
767
+ this (condition , value , typeHandler , false );
768
+ }
769
+
770
+ protected Criterion (String condition , Object value ) {
771
+ this (condition , value , null , false );
772
+ }
773
+
774
+ protected Criterion (String condition , Object value , Object secondValue , String typeHandler ) {
775
+ this (condition , value , secondValue , typeHandler , false );
776
+ }
777
+
778
+ protected Criterion (String condition , Object value , Object secondValue ) {
779
+ this (condition , value , secondValue , null , false );
780
+ }
781
+
782
+ protected Criterion (String condition , boolean isOr ) {
559
783
super ();
560
784
this .condition = condition ;
561
785
this .typeHandler = null ;
562
786
this .noValue = true ;
787
+ this .andOr = isOr ? "or" : "and" ;
563
788
}
564
789
565
- protected Criterion (String condition , Object value , String typeHandler ) {
790
+ protected Criterion (String condition , Object value , String typeHandler , boolean isOr ) {
566
791
super ();
567
792
this .condition = condition ;
568
793
this .value = value ;
569
794
this .typeHandler = typeHandler ;
795
+ this .andOr = isOr ? "or" : "and" ;
570
796
if (value instanceof Collection <?>) {
571
797
this .listValue = true ;
572
798
} else {
573
799
this .singleValue = true ;
574
800
}
575
801
}
576
802
577
- protected Criterion (String condition , Object value ) {
578
- this (condition , value , null );
803
+ protected Criterion (String condition , Object value , boolean isOr ) {
804
+ this (condition , value , null , isOr );
579
805
}
580
806
581
- protected Criterion (String condition , Object value , Object secondValue , String typeHandler ) {
807
+ protected Criterion (String condition , Object value , Object secondValue , String typeHandler , boolean isOr ) {
582
808
super ();
583
809
this .condition = condition ;
584
810
this .value = value ;
585
811
this .secondValue = secondValue ;
586
812
this .typeHandler = typeHandler ;
587
813
this .betweenValue = true ;
814
+ this .andOr = isOr ? "or" : "and" ;
588
815
}
589
816
590
- protected Criterion (String condition , Object value , Object secondValue ) {
591
- this (condition , value , secondValue , null );
817
+ protected Criterion (String condition , Object value , Object secondValue , boolean isOr ) {
818
+ this (condition , value , secondValue , null , isOr );
592
819
}
593
820
594
821
public String getCondition () {
@@ -603,6 +830,14 @@ public Object getSecondValue() {
603
830
return secondValue ;
604
831
}
605
832
833
+ public String getAndOr () {
834
+ return andOr ;
835
+ }
836
+
837
+ public void setAndOr (String andOr ) {
838
+ this .andOr = andOr ;
839
+ }
840
+
606
841
public boolean isNoValue () {
607
842
return noValue ;
608
843
}
0 commit comments