@@ -464,7 +464,7 @@ public JSONObject parseCorrectRequest(RequestMethod method, String tag, int vers
464
464
}
465
465
466
466
if (StringUtil .isEmpty (tag , true )) {
467
- throw new IllegalArgumentException ("请在最外层设置 tag !一般是 Table 名,例如 \" tag\" : \" User\" " );
467
+ throw new IllegalArgumentException ("请在最外层传 tag !一般是 Table 名,例如 \" tag\" : \" User\" " );
468
468
}
469
469
470
470
//获取指定的JSON结构 <<<<<<<<<<<<
@@ -475,17 +475,28 @@ public JSONObject parseCorrectRequest(RequestMethod method, String tag, int vers
475
475
} catch (Exception e ) {
476
476
error = e .getMessage ();
477
477
}
478
- if (object == null ) {//empty表示随意操作 || object.isEmpty()) {
479
- throw new UnsupportedOperationException ("非开放请求必须是后端 Request 表中校验规则允许的操作!\n " + error );
478
+ if (object == null ) { //empty表示随意操作 || object.isEmpty()) {
479
+ throw new UnsupportedOperationException ("找不到 version: " + version + ", method: " + method .name () + ", tag: " + tag + " 对应的 structure !"
480
+ + "非开放请求必须是后端 Request 表中校验规则允许的操作!\n " + error + "\n 如果需要则在 Request 表中新增配置!" );
480
481
}
481
482
482
- JSONObject target = null ;
483
- if (apijson .JSONObject .isTableKey (tag ) && object .containsKey (tag ) == false ) {//tag是table名
484
- target = new JSONObject (true );
485
- target .put (tag , object );
486
- } else {
487
- target = object ;
483
+ JSONObject target = object ;
484
+ if (object .containsKey (tag ) == false ) { //tag 是 Table 名或 Table[]
485
+
486
+ boolean isArrayKey = tag .endsWith (":[]" ); // JSONRequest.isArrayKey(tag);
487
+ String key = isArrayKey ? tag .substring (0 , tag .length () - 3 ) : tag ;
488
+
489
+ if (apijson .JSONObject .isTableKey (key )) {
490
+ if (isArrayKey ) { //自动为 tag = Comment:[] 的 { ... } 新增键值对 "Comment[]":[] 为 { "Comment[]":[], ... }
491
+ target .put (key + "[]" , new JSONArray ());
492
+ }
493
+ else { //自动为 tag = Comment 的 { ... } 包一层为 { "Comment": { ... } }
494
+ target = new JSONObject (true );
495
+ target .put (tag , object );
496
+ }
497
+ }
488
498
}
499
+
489
500
//获取指定的JSON结构 >>>>>>>>>>>>>>
490
501
491
502
//JSONObject clone 浅拷贝没用,Structure.parse 会导致 structure 里面被清空,第二次从缓存里取到的就是 {}
@@ -511,9 +522,13 @@ public static JSONObject extendResult(JSONObject object, int code, String msg) {
511
522
if (object == null ) {
512
523
object = new JSONObject (true );
513
524
}
525
+ if (object .containsKey (JSONResponse .KEY_OK ) == false ) {
526
+ object .put (JSONResponse .KEY_OK , JSONResponse .isSuccess (code ));
527
+ }
514
528
if (object .containsKey (JSONResponse .KEY_CODE ) == false ) {
515
529
object .put (JSONResponse .KEY_CODE , code );
516
530
}
531
+
517
532
String m = StringUtil .getString (object .getString (JSONResponse .KEY_MSG ));
518
533
if (m .isEmpty () == false ) {
519
534
msg = m + " ;\n " + StringUtil .getString (msg );
@@ -738,9 +753,29 @@ public JSONObject onObjectParse(final JSONObject request
738
753
int index = parentPath .lastIndexOf ("]/" );
739
754
if (index >= 0 ) {
740
755
int total = rp .getIntValue (JSONResponse .KEY_COUNT );
741
- putQueryResult (parentPath .substring (0 , index ) + "]/" + JSONResponse .KEY_TOTAL , total );
742
-
743
- if (total <= arrayConfig .getCount ()*arrayConfig .getPage ()) {
756
+
757
+ String pathPrefix = parentPath .substring (0 , index ) + "]/" ;
758
+ putQueryResult (pathPrefix + JSONResponse .KEY_TOTAL , total );
759
+
760
+ //详细的分页信息,主要为 PC 端提供
761
+ int count = arrayConfig .getCount ();
762
+ int page = arrayConfig .getPage ();
763
+ int max = (int ) ((total - 1 )/count );
764
+ if (max < 0 ) {
765
+ max = 0 ;
766
+ }
767
+
768
+ JSONObject pagination = new JSONObject (true );
769
+ pagination .put (JSONResponse .KEY_TOTAL , total );
770
+ pagination .put (JSONRequest .KEY_COUNT , count );
771
+ pagination .put (JSONRequest .KEY_PAGE , page );
772
+ pagination .put (JSONResponse .KEY_MAX , max );
773
+ pagination .put (JSONResponse .KEY_MORE , page < max );
774
+ pagination .put (JSONResponse .KEY_FIRST , page == 0 );
775
+ pagination .put (JSONResponse .KEY_LAST , page == max );
776
+ putQueryResult (pathPrefix + JSONResponse .KEY_INFO , pagination );
777
+
778
+ if (total <= count *page ) {
744
779
query = JSONRequest .QUERY_TOTAL ;//数量不够了,不再往后查询
745
780
}
746
781
}
@@ -1032,7 +1067,7 @@ else if (join != null){
1032
1067
j .setTargetKey (targetKey );
1033
1068
j .setKeyAndType (key );
1034
1069
j .setRequest (getJoinObject (table , tableObj , key ));
1035
- j .setOutter ((JSONObject ) e .getValue ());
1070
+ j .setOuter ((JSONObject ) e .getValue ());
1036
1071
1037
1072
joinList .add (j );
1038
1073
0 commit comments