33import org .apache .commons .lang3 .StringUtils ;
44
55import java .util .ArrayList ;
6+ import java .util .LinkedList ;
67import java .util .List ;
78import java .util .Map ;
89
@@ -26,67 +27,45 @@ public QueryBuilder select(String select) {
2627 public class Condition {
2728 private List <ConditionParameter > conditions = new ArrayList <>();
2829
29- public Splice notNullCondition (String conditionSql ,String paramKey , Object paramVal ) {
30+ public Splice condition (String conditionSql ,String paramKey , Object paramVal ) {
3031 if (paramVal !=null ) {
3132 conditions .add (new ConditionParameter (paramKey , paramVal , conditionSql ));
3233 }else {
33- conditions . add ( new ConditionParameter ( "1=1" ) );
34+ splice . remove ( );
3435 }
3536 return splice ;
3637 }
3738
38- public Splice condition (String conditionSql ,String paramKey , Object paramVal ) {
39- conditions .add (new ConditionParameter (paramKey , paramVal , conditionSql ));
40- return splice ;
41- }
4239
43- public Splice notNullCondition (String conditionSql ,Map <String ,Object > map ) {
40+ public Splice condition (String conditionSql ,Map <String ,Object > map ) {
4441 if (map !=null &&map .size ()>0 ) {
4542 conditions .add (new ConditionParameter (map , conditionSql ));
4643 }else {
47- conditions . add ( new ConditionParameter ( "1=1" ) );
44+ splice . remove ( );
4845 }
4946 return splice ;
5047 }
5148
52- public Splice condition (String conditionSql ,Map <String ,Object > map ) {
53- conditions .add (new ConditionParameter (map , conditionSql ));
54- return splice ;
55- }
56-
57- public Splice condition (String conditionSql ) {
58- conditions .add (new ConditionParameter (conditionSql ));
59- return splice ;
60- }
6149
62- public Splice notNullCondition (String conditionSql ,Object paramVal ) {
50+ public Splice condition (String conditionSql ,Object paramVal ) {
6351 if (paramVal !=null ) {
6452 conditions .add (new ConditionParameter (paramVal , conditionSql ));
6553 }else {
66- conditions . add ( new ConditionParameter ( "1=1" ) );
54+ splice . remove ( );
6755 }
6856 return splice ;
6957 }
7058
71- public Splice condition (String conditionSql ,Object paramVal ) {
72- conditions .add (new ConditionParameter ( paramVal , conditionSql ));
73- return splice ;
74- }
7559
76- public Splice notNullCondition (String conditionSql ,Object ... paramVal ) {
60+ public Splice condition (String conditionSql ,Object ... paramVal ) {
7761 if (paramVal !=null &¶mVal .length >0 ) {
7862 conditions .add (new ConditionParameter (StringUtils .join (paramVal , "," ), conditionSql ));
7963 }else {
80- conditions . add ( new ConditionParameter ( "1=1" ) );
64+ splice . remove ( );
8165 }
8266 return splice ;
8367 }
8468
85- public Splice condition (String conditionSql ,Object ... paramVal ) {
86- conditions .add (new ConditionParameter (StringUtils .join (paramVal ,"," ), conditionSql ));
87- return splice ;
88- }
89-
9069 }
9170
9271 public class Splice {
@@ -116,6 +95,8 @@ public Condition splice(String splice) {
11695 return condition ;
11796 }
11897
98+
99+
119100 public QueryBuilder orderBy (String orderByStr ) {
120101 bySql = String .format (" order by %s" ,orderByStr );
121102 return QueryBuilder .this ;
@@ -129,6 +110,12 @@ public QueryBuilder groupBy(String groupBySql) {
129110 public Query builder () {
130111 return new Query (select , condition .conditions , splice .splices , bySql );
131112 }
113+
114+ public void remove () {
115+ if (splices .size ()>0 ) {
116+ splices .remove (splices .size ()-1 );
117+ }
118+ }
132119 }
133120
134121 public Query builder () {
0 commit comments