@@ -254,23 +254,29 @@ public AbstractSQLConfig setGroup(String group) {
254
254
}
255
255
@ JSONField (serialize = false )
256
256
public String getGroupString () {
257
+ //TODO 加上子表的group
258
+
257
259
group = StringUtil .getTrimedString (group );
258
260
if (group .isEmpty ()) {
259
261
return "" ;
260
262
}
261
263
262
- if (isPrepared ()) { //不能通过 ? 来代替,因为SQLExecutor statement.setString后 GROUP BY 'userId' 有单引号,只能返回一条数据,必须去掉单引号才行!
263
- String [] keys = StringUtil .split (group );
264
- if (keys != null && keys .length > 0 ) {
265
- for (int i = 0 ; i < keys .length ; i ++) {
266
- if (StringUtil .isName (keys [i ]) == false ) {
267
- throw new IllegalArgumentException ("@group:value 中 value里面用 , 分割的每一项都必须是1个单词!并且不要有空格!" );
268
- }
264
+ String [] keys = StringUtil .split (group );
265
+ if (keys == null || keys .length <= 0 ) {
266
+ return "" ;
267
+ }
268
+
269
+ for (int i = 0 ; i < keys .length ; i ++) {
270
+ if (isPrepared ()) { //不能通过 ? 来代替,因为SQLExecutor statement.setString后 GROUP BY 'userId' 有单引号,只能返回一条数据,必须去掉单引号才行!
271
+ if (StringUtil .isName (keys [i ]) == false ) {
272
+ throw new IllegalArgumentException ("@group:value 中 value里面用 , 分割的每一项都必须是1个单词!并且不要有空格!" );
269
273
}
270
274
}
275
+
276
+ keys [i ] = getKey (keys [i ]);
271
277
}
272
278
273
- return " GROUP BY " + group ;
279
+ return " GROUP BY " + StringUtil . getString ( keys ) ;
274
280
}
275
281
276
282
@ Override
@@ -311,6 +317,8 @@ public AbstractSQLConfig setOrder(String order) {
311
317
}
312
318
@ JSONField (serialize = false )
313
319
public String getOrderString () {
320
+ //TODO 加上子表的order
321
+
314
322
order = StringUtil .getTrimedString (order );
315
323
if (order .isEmpty ()) {
316
324
return "" ;
@@ -321,30 +329,37 @@ public String getOrderString() {
321
329
if (order .contains ("-" )) {
322
330
order = order .replaceAll ("-" , " DESC " );
323
331
}
324
-
332
+
325
333
//TODO column, order, group 都改用 List<String> 存储!!!,并且每个字段都要加 Table. 前缀!
326
- if (isPrepared ()) { //不能通过 ? 来代替,SELECT 'id','name' 返回的就是 id:"id", name:"name",而不是数据库里的值!
327
- String [] keys = StringUtil .split (order );
328
- if (keys != null && keys .length > 0 ) {
329
- String origin ;
330
- int index ;
331
- for (int i = 0 ; i < keys .length ; i ++) {
332
- index = keys [i ].trim ().endsWith (" ASC" ) ? keys [i ].lastIndexOf (" ASC" ) : -1 ; //StringUtil.split返回数组中,子项不会有null
333
- if (index < 0 ) {
334
- index = keys [i ].trim ().endsWith (" DESC" ) ? keys [i ].lastIndexOf (" DESC" ) : -1 ;
335
- }
336
- origin = index < 0 ? keys [i ] : keys [i ].substring (0 , index );
334
+ String [] keys = StringUtil .split (order );
335
+ if (keys == null || keys .length <= 0 ) {
336
+ return "" ;
337
+ }
337
338
338
- //这里既不对origin trim,也不对 ASC/DESC ignoreCase,希望前端严格传没有任何空格的字符串过来,减少传输数据量,节约服务器性能
339
- if (StringUtil .isName (origin ) == false ) {
340
- throw new IllegalArgumentException ("预编译模式下 @order:value 中 value里面用 , 分割的每一项"
341
- + " column+ / column- 中 column必须是1个单词!并且不要有多余的空格!" );
342
- }
339
+ String origin ;
340
+ String sort ;
341
+ int index ;
342
+ for (int i = 0 ; i < keys .length ; i ++) {
343
+ index = keys [i ].trim ().endsWith (" ASC" ) ? keys [i ].lastIndexOf (" ASC" ) : -1 ; //StringUtil.split返回数组中,子项不会有null
344
+ if (index < 0 ) {
345
+ index = keys [i ].trim ().endsWith (" DESC" ) ? keys [i ].lastIndexOf (" DESC" ) : -1 ;
346
+ sort = index <= 0 ? "" : " DESC " ;
347
+ } else {
348
+ sort = " ASC " ;
349
+ }
350
+ origin = index < 0 ? keys [i ] : keys [i ].substring (0 , index );
351
+
352
+ if (isPrepared ()) { //不能通过 ? 来代替,SELECT 'id','name' 返回的就是 id:"id", name:"name",而不是数据库里的值!
353
+ //这里既不对origin trim,也不对 ASC/DESC ignoreCase,希望前端严格传没有任何空格的字符串过来,减少传输数据量,节约服务器性能
354
+ if (StringUtil .isName (origin ) == false ) {
355
+ throw new IllegalArgumentException ("预编译模式下 @order:value 中 value里面用 , 分割的每一项"
356
+ + " column+ / column- 中 column必须是1个单词!并且不要有多余的空格!" );
343
357
}
344
358
}
359
+ keys [i ] = getKey (origin ) + sort ;
345
360
}
346
-
347
- return " ORDER BY " + order ;
361
+
362
+ return " ORDER BY " + StringUtil . getString ( keys ) ;
348
363
}
349
364
350
365
@@ -699,7 +714,7 @@ else if (prior && andList.isEmpty() == false) {
699
714
i ++;
700
715
}
701
716
}
702
-
717
+
703
718
if (prior ) {
704
719
andList .add (i , key ); //userId的优先级不能比id高 0, key);
705
720
} else {
@@ -800,11 +815,11 @@ else if ("!".equals(ce.getKey())) {
800
815
jc .setMain (false ).setPrepared (isPrepared ()).setPreparedValueList (new ArrayList <Object >());
801
816
js = jc .getWhereString (false );
802
817
jc .setMain (isMain );
803
-
818
+
804
819
if (StringUtil .isEmpty (js , true )) {
805
820
continue ;
806
821
}
807
-
822
+
808
823
whereString = " ( "
809
824
+ getCondition (
810
825
Logic .isNot (logic ),
@@ -813,7 +828,7 @@ else if ("!".equals(ce.getKey())) {
813
828
+ " ( " + js + " ) "
814
829
)
815
830
+ " ) " ;
816
-
831
+
817
832
preparedValueList .addAll (jc .getPreparedValueList ());
818
833
break ;
819
834
//可能 LEFT JOIN 和 INNER JOIN 同时存在 default:
@@ -915,7 +930,7 @@ public AbstractSQLConfig setPreparedValueList(List<Object> preparedValueList) {
915
930
this .preparedValueList = preparedValueList ;
916
931
return this ;
917
932
}
918
-
933
+
919
934
//$ search <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
920
935
/**search key match value
921
936
* @param in
@@ -1412,7 +1427,7 @@ public String getJoinString() throws Exception {
1412
1427
+ j .getName () + " ON " + jc .getTable () + "." + j .getKey () + " = "
1413
1428
+ j .getTargetName () + "." + j .getTargetKey ();
1414
1429
jc .setMain (false ).setKeyPrefix (true );
1415
-
1430
+
1416
1431
preparedValueList .addAll (jc .getPreparedValueList ());
1417
1432
break ;
1418
1433
default :
0 commit comments