@@ -464,7 +464,7 @@ public JSONObject parseCorrectRequest(RequestMethod method, String tag, int vers
464464 }
465465
466466 if (StringUtil .isEmpty (tag , true )) {
467- throw new IllegalArgumentException ("请在最外层设置 tag !一般是 Table 名,例如 \" tag\" : \" User\" " );
467+ throw new IllegalArgumentException ("请在最外层传 tag !一般是 Table 名,例如 \" tag\" : \" User\" " );
468468 }
469469
470470 //获取指定的JSON结构 <<<<<<<<<<<<
@@ -475,17 +475,28 @@ public JSONObject parseCorrectRequest(RequestMethod method, String tag, int vers
475475 } catch (Exception e ) {
476476 error = e .getMessage ();
477477 }
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 表中新增配置!" );
480481 }
481482
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+ }
488498 }
499+
489500 //获取指定的JSON结构 >>>>>>>>>>>>>>
490501
491502 //JSONObject clone 浅拷贝没用,Structure.parse 会导致 structure 里面被清空,第二次从缓存里取到的就是 {}
@@ -511,9 +522,13 @@ public static JSONObject extendResult(JSONObject object, int code, String msg) {
511522 if (object == null ) {
512523 object = new JSONObject (true );
513524 }
525+ if (object .containsKey (JSONResponse .KEY_OK ) == false ) {
526+ object .put (JSONResponse .KEY_OK , JSONResponse .isSuccess (code ));
527+ }
514528 if (object .containsKey (JSONResponse .KEY_CODE ) == false ) {
515529 object .put (JSONResponse .KEY_CODE , code );
516530 }
531+
517532 String m = StringUtil .getString (object .getString (JSONResponse .KEY_MSG ));
518533 if (m .isEmpty () == false ) {
519534 msg = m + " ;\n " + StringUtil .getString (msg );
@@ -738,9 +753,29 @@ public JSONObject onObjectParse(final JSONObject request
738753 int index = parentPath .lastIndexOf ("]/" );
739754 if (index >= 0 ) {
740755 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 ) {
744779 query = JSONRequest .QUERY_TOTAL ;//数量不够了,不再往后查询
745780 }
746781 }
@@ -1032,7 +1067,7 @@ else if (join != null){
10321067 j .setTargetKey (targetKey );
10331068 j .setKeyAndType (key );
10341069 j .setRequest (getJoinObject (table , tableObj , key ));
1035- j .setOutter ((JSONObject ) e .getValue ());
1070+ j .setOuter ((JSONObject ) e .getValue ());
10361071
10371072 joinList .add (j );
10381073
0 commit comments