@@ -24,10 +24,12 @@ var CodeUtil = {
24
24
* @param tableList
25
25
* @return parseComment
26
26
*/
27
- parseComment : function ( reqStr , tableList ) { //怎么都获取不到真正的长度,cols不行,默认20不变,maxLineLength不行,默认undefined不变 , maxLineLength) {
27
+ parseComment : function ( reqStr , tableList , method ) { //怎么都获取不到真正的长度,cols不行,默认20不变,maxLineLength不行,默认undefined不变 , maxLineLength) {
28
28
if ( StringUtil . isEmpty ( reqStr ) ) {
29
29
return '' ;
30
30
}
31
+ method = method == null ? 'GET' : method . toUpperCase ( ) ;
32
+
31
33
32
34
var lines = reqStr . split ( '\n' ) ;
33
35
var line ;
@@ -50,7 +52,7 @@ var CodeUtil = {
50
52
if ( line . endsWith ( '{' ) ) { //对象,判断是不是Table,再加对应的注释
51
53
depth ++ ;
52
54
names [ depth ] = key ;
53
- comment = CodeUtil . getComment4Request ( tableList , null , key , null ) ;
55
+ comment = CodeUtil . getComment4Request ( tableList , null , key , null , method ) ;
54
56
}
55
57
else {
56
58
if ( line . endsWith ( ',' ) ) {
@@ -67,7 +69,8 @@ var CodeUtil = {
67
69
else { //其它,直接在后面加上注释
68
70
var isArray = line . endsWith ( '[' ) ;
69
71
// alert('depth = ' + depth + '; line = ' + line + '; isArray = ' + isArray);
70
- comment = value == 'null' ? ' ! null无效' : CodeUtil . getComment4Request ( tableList , names [ depth ] , key , isArray ? '' : line . substring ( index + 2 ) . trim ( ) ) ;
72
+ comment = value == 'null' ? ' ! null无效' : CodeUtil . getComment4Request ( tableList , names [ depth ] , key
73
+ , isArray ? '' : line . substring ( index + 2 ) . trim ( ) , method ) ;
71
74
}
72
75
}
73
76
@@ -750,21 +753,24 @@ var CodeUtil = {
750
753
* @param key
751
754
* @param value
752
755
*/
753
- getComment4Request : function ( tableList , name , key , value ) {
754
- // alert('name = ' + name + '; key = ' + key + '; value = ' + value);
756
+ getComment4Request : function ( tableList , name , key , value , method ) {
757
+ // alert('name = ' + name + '; key = ' + key + '; value = ' + value + '; method = ' + method );
755
758
756
759
if ( key == null ) {
757
760
return '' ;
758
761
}
759
762
760
763
if ( value == null || value instanceof Object ) {
761
764
if ( JSONObject . isArrayKey ( key ) ) {
765
+ if ( method != 'GET' ) {
766
+ return ' ! key[]:{}只支持GET方法!' ;
767
+ }
762
768
var arrName = JSONResponse . getSimpleName ( key . substring ( 0 , key . lastIndexOf ( '[]' ) ) ) ;
763
769
return CodeUtil . getComment ( '数组' + ( JSONObject . isTableKey ( arrName ) ? ',提取' + arrName : '' ) , false , ' ' ) ;
764
770
}
765
771
if ( JSONObject . isTableKey ( key ) ) {
766
772
var objName = JSONResponse . getSimpleName ( key ) ;
767
- var c = CodeUtil . getCommentFromDoc ( tableList , objName , null ) ;
773
+ var c = CodeUtil . getCommentFromDoc ( tableList , objName , null , method ) ;
768
774
return StringUtil . isEmpty ( c ) ? ' ! 表不存在!' : CodeUtil . getComment ( c , false , ' ' ) ;
769
775
}
770
776
@@ -811,7 +817,7 @@ var CodeUtil = {
811
817
}
812
818
return '' ;
813
819
}
814
- var c = CodeUtil . getCommentFromDoc ( tableList , name , key ) ;
820
+ var c = CodeUtil . getCommentFromDoc ( tableList , name , key , method ) ;
815
821
return StringUtil . isEmpty ( c ) ? ' ! 字段不存在!' : CodeUtil . getComment ( c , false , ' ' ) ;
816
822
}
817
823
@@ -838,10 +844,11 @@ var CodeUtil = {
838
844
* @param tableList
839
845
* @param tableName
840
846
* @param columnName
847
+ * @param method
841
848
* @return {* }
842
849
*/
843
- getCommentFromDoc : function ( tableList , tableName , columnName ) {
844
- log ( 'getCommentFromDoc tableName = ' + tableName + '; columnName = ' + columnName + '; tableList = \n' + JSON . stringify ( tableList ) ) ;
850
+ getCommentFromDoc : function ( tableList , tableName , columnName , method ) {
851
+ log ( 'getCommentFromDoc tableName = ' + tableName + '; columnName = ' + columnName + '; method = ' + method + '; tableList = \n' + JSON . stringify ( tableList ) ) ;
845
852
846
853
if ( tableList == null || tableList . length <= 0 ) {
847
854
return '...' ;
@@ -899,38 +906,50 @@ var CodeUtil = {
899
906
key = columnName . substring ( 0 , columnName . length - 2 ) ;
900
907
}
901
908
else if ( columnName . endsWith ( "+" ) ) { //延长,PUT查询时处理
902
- //if (method == PUT) {//不为PUT就抛异常
903
- fun = '增加 或 扩展 ' ;
909
+ if ( method != 'PUT' ) { //不为PUT就抛异常
910
+ return ' ! 功能符 + - 只能用于PUT请求!' ;
911
+ }
912
+ fun = '增加/扩展' ;
904
913
key = columnName . substring ( 0 , columnName . length - 1 ) ;
905
- //}
906
914
}
907
915
else if ( columnName . endsWith ( "-" ) ) { //缩减,PUT查询时处理
908
- //if (method == PUT) {//不为PUT就抛异常
909
- fun = '减少 或 去除' ;
916
+ if ( method != 'PUT' ) { //不为PUT就抛异常
917
+ return ' ! 功能符 + - 只能用于PUT请求!' ;
918
+ }
919
+ fun = '减少/去除' ;
910
920
key = columnName . substring ( 0 , columnName . length - 1 ) ;
911
- //}
912
921
}
913
922
else {
914
923
fun = '' ;
915
924
key = new String ( columnName ) ;
916
925
}
917
926
918
927
919
- var logic = '' ;
920
- //if (RequestMethod.isQueryMethod(method)) {//逻辑运算符仅供GET,HEAD方法使用
928
+ var logic ;
921
929
if ( key . endsWith ( "&" ) ) {
930
+ if ( fun . length <= 0 ) {
931
+ return ' ! 逻辑运算符 & | 后面必须接其它功能符!' ;
932
+ }
922
933
logic = '符合全部' ;
923
934
}
924
935
else if ( key . endsWith ( "|" ) ) {
936
+ if ( fun . length <= 0 ) {
937
+ return ' ! 逻辑运算符 & | 后面必须接其它功能符!' ;
938
+ }
925
939
logic = '符合任意' ;
926
940
}
927
941
else if ( key . endsWith ( "!" ) ) {
928
942
logic = '都不符合' ;
929
943
}
930
- else { }
931
- //}
944
+ else {
945
+ logic = '' ;
946
+ }
947
+
932
948
933
949
if ( logic . length > 0 ) {
950
+ if ( method != 'GET' && method != 'HEAD' && method != 'GETS' && method != 'HEADS' ) { //逻辑运算符仅供GET,HEAD方法使用
951
+ return ' ! 逻辑运算符 & | ! 只能用于查询(GET,HEAD,GETS,HEADS)请求!' ;
952
+ }
934
953
key = key . substring ( 0 , key . length - 1 ) ;
935
954
}
936
955
@@ -955,9 +974,9 @@ var CodeUtil = {
955
974
continue ;
956
975
}
957
976
958
- var p = ( at . length <= 0 ? '' : at + ' > ' )
959
- + ( fun . length <= 0 ? '' : fun + ' > ' )
960
- + ( logic . length <= 0 ? '' : logic + ' > ' ) ;
977
+ var p = ( at . length <= 0 ? '' : at + ' < ' )
978
+ + ( fun . length <= 0 ? '' : fun + ' < ' )
979
+ + ( logic . length <= 0 ? '' : logic + ' < ' ) ;
961
980
return ( p . length <= 0 ? '' : p + key + ': ' ) + column . COLUMN_COMMENT ;
962
981
}
963
982
0 commit comments