Skip to content

Commit 3d8d6f2

Browse files
committed
Sever:新增支持Response校验;JSONObject,JSONRequest,JSONResponse等部分处理转至StringUtil;Parser,ObjectParser,QueryConfig等方法相关判断移至RequestMethod
1 parent 6186f39 commit 3d8d6f2

13 files changed

Lines changed: 206 additions & 172 deletions

File tree

‎APIJSON(Server)/APIJSON(Eclipse_JEE)/src/main/java/apijson/demo/server/APIJSONApplication.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
@SpringBootApplication
3030
public class APIJSONApplication {
3131

32-
public static void main(String[] args) {
32+
public static void main(String[] args) throws Exception {
3333
SpringApplication.run(APIJSONApplication.class, args);
3434

3535
try {
@@ -38,6 +38,8 @@ public static void main(String[] args) {
3838
e.printStackTrace();
3939
}
4040

41+
// Structure.init();
42+
4143
try {
4244
Structure.test();
4345
} catch (Exception e) {

‎APIJSON(Server)/APIJSON(Eclipse_JEE)/src/main/java/apijson/demo/server/model/Moment.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
* </pre>
4141
*/
4242
@APIJSONRequest(
43-
method = {RequestMethod.GET, RequestMethod.HEAD, RequestMethod.POST, RequestMethod.PUT, RequestMethod.DELETE},
43+
method = {RequestMethod.GET, RequestMethod.POST_GET, RequestMethod.HEAD, RequestMethod.POST, RequestMethod.PUT, RequestMethod.DELETE},
4444
POST = "{\"disallow\": \"id\", \"necessary\": \"userId,pictureList\"}",
4545
PUT = "{\"disallow\": \"userId,date\", \"necessary\": \"id\"}",
4646
DELETE = "{\"necessary\": \"id\"}"

‎APIJSON(Server)/APIJSON(Eclipse_JEE)/src/main/java/apijson/demo/server/model/User.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
* </pre>
5151
*/
5252
@APIJSONRequest(
53-
method = {RequestMethod.GET, RequestMethod.HEAD, RequestMethod.PUT, RequestMethod.DELETE},
53+
method = {RequestMethod.GET, RequestMethod.POST_GET, RequestMethod.HEAD, RequestMethod.PUT, RequestMethod.DELETE},
5454
POST = "{\"User\": {\"disallow\": \"id\", \"necessary\": \"name,phone\"}, \"necessary\": \"loginPassword,verify\"}",
5555
PUT = "{\"disallow\": \"phone\", \"necessary\": \"id\"}"
5656
)

‎APIJSON(Server)/APIJSON(Eclipse_JEE)/src/main/java/zuo/biao/apijson/JSONObject.java‎

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
package zuo.biao.apijson;
1616

1717
import static zuo.biao.apijson.StringUtil.UTF_8;
18-
import static zuo.biao.apijson.StringUtil.bigAlphaPattern;
19-
import static zuo.biao.apijson.StringUtil.namePattern;
2018

2119
import java.io.UnsupportedEncodingException;
2220
import java.net.URLDecoder;
@@ -218,14 +216,7 @@ public static boolean isArrayKey(String key) {
218216
* @return
219217
*/
220218
public static boolean isTableKey(String key) {
221-
return isWord(key) && bigAlphaPattern.matcher(key.substring(0, 1)).matches();
222-
}
223-
/**判断是否为词,只能包含字母,数字或下划线
224-
* @param key
225-
* @return
226-
*/
227-
public static boolean isWord(String key) {
228-
return StringUtil.isNotEmpty(key, false) && namePattern.matcher(key).matches();
219+
return StringUtil.isBigWord(key);
229220
}
230221
//judge >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
231222

@@ -252,9 +243,6 @@ public JSONObject setColumn(String keys) {
252243
put(KEY_COLUMN, keys);
253244
return this;
254245
}
255-
public String getColumn() {
256-
return getString(KEY_COLUMN);
257-
}
258246

259247
/**set keys for group by
260248
* @param keys key0, key1, key2 ...
@@ -271,9 +259,6 @@ public JSONObject setGroup(String keys) {
271259
put(KEY_GROUP, keys);
272260
return this;
273261
}
274-
public String getGroup() {
275-
return getString(KEY_GROUP);
276-
}
277262

278263
/**set keys for having
279264
* @param keys count(key0) > 1, sum(key1) <= 5, function2(key2) ? value2 ...
@@ -290,9 +275,6 @@ public JSONObject setHaving(String keys) {
290275
put(KEY_HAVING, keys);
291276
return this;
292277
}
293-
public String getHaving() {
294-
return getString(KEY_HAVING);
295-
}
296278

297279
/**set keys for order by
298280
* @param keys key0, key1+, key2- ...
@@ -309,9 +291,6 @@ public JSONObject setOrder(String keys) {
309291
put(KEY_ORDER, keys);
310292
return this;
311293
}
312-
public String getOrder() {
313-
return getString(KEY_ORDER);
314-
}
315294

316295

317296
//JSONObject内关键词 key >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

‎APIJSON(Server)/APIJSON(Eclipse_JEE)/src/main/java/zuo/biao/apijson/JSONRequest.java‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,6 @@ public JSONRequest setQuery(int query) {
9898
put(KEY_QUERY, query);
9999
return this;
100100
}
101-
public int getQuery() {
102-
return getIntValue(KEY_QUERY);
103-
}
104-
105101
/**
106102
* @param count
107103
* @return
@@ -110,10 +106,6 @@ public JSONRequest setCount(int count) {
110106
put(KEY_COUNT, count);
111107
return this;
112108
}
113-
public int getCount() {
114-
return getIntValue(KEY_COUNT);
115-
}
116-
117109
/**
118110
* @param page
119111
* @return
@@ -122,9 +114,6 @@ public JSONRequest setPage(int page) {
122114
put(KEY_PAGE, page);
123115
return this;
124116
}
125-
public int getPage() {
126-
return getIntValue(KEY_PAGE);
127-
}
128117
//array object >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
129118

130119

‎APIJSON(Server)/APIJSON(Eclipse_JEE)/src/main/java/zuo/biao/apijson/JSONResponse.java‎

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
package zuo.biao.apijson;
1616

17-
import static zuo.biao.apijson.StringUtil.bigAlphaPattern;
18-
1917
import java.util.List;
2018
import java.util.Set;
2119

@@ -26,8 +24,8 @@
2624
* @author Lemon
2725
* @see #getList
2826
* @see #toArray
29-
* @use JSONResponse response = new JSONResponse(...);
30-
* <br> JSONArray array = JSONResponse.toArray(response.getJSONObject(KEY_ARRAY));//not a must
27+
* @use JSONResponse response = new JSONResponse(json);
28+
* <br> JSONArray array = JSONResponse.toArray(response.getJSONObject("[]"));//not a must
3129
* <br> User user = JSONResponse.getObject(response, User.class);//not a must
3230
* <br> List<Comment> list = JSONResponse.getList(response.getJSONObject("Comment[]"), Comment.class);//not a must
3331
*/
@@ -451,16 +449,7 @@ public static String replaceArray(String key) {
451449
* @return empty ? "list" : key + "List" 且首字母小写
452450
*/
453451
public static String getArrayKey(String key) {
454-
key = StringUtil.getNoBlankString(key);
455-
if (key.isEmpty()) {
456-
return "list";
457-
}
458-
459-
String first = key.substring(0, 1);
460-
if (bigAlphaPattern.matcher(first).matches()) {
461-
key = first.toLowerCase() + key.substring(1, key.length());
462-
}
463-
return key + "List";
452+
return StringUtil.addSuffix(key, "list");
464453
}
465454

466455
/**获取简单名称

‎APIJSON(Server)/APIJSON(Eclipse_JEE)/src/main/java/zuo/biao/apijson/RequestMethod.java‎

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,42 @@ public enum RequestMethod {
5252
/**
5353
* 删除数据
5454
*/
55-
DELETE
55+
DELETE;
56+
57+
58+
/**是否为GET请求方法
59+
* @param method
60+
* @param containPrivate 包含私密(非明文)获取方法POST_GET
61+
* @return
62+
*/
63+
public static boolean isGetMethod(RequestMethod method, boolean containPrivate) {
64+
boolean is = method == null || method == GET;
65+
return containPrivate == false ? is : is || method == POST_GET;
66+
}
67+
68+
/**是否为HEAD请求方法
69+
* @param method
70+
* @param containPrivate 包含私密(非明文)获取方法POST_HEAD
71+
* @return
72+
*/
73+
public static boolean isHeadMethod(RequestMethod method, boolean containPrivate) {
74+
boolean is = method == HEAD;
75+
return containPrivate == false ? is : is || method == POST_HEAD;
76+
}
77+
78+
/**是否为查询的请求方法
79+
* @param method
80+
* @return 读操作(GET型或HEAD型) - true, 写操作(POST,PUT,DELETE) - false
81+
*/
82+
public static boolean isQueryMethod(RequestMethod method) {
83+
return isGetMethod(method, true) || isHeadMethod(method, true);
84+
}
85+
86+
/**是否为开放(不限制请求的结构或内容;明文,浏览器能直接访问及查看)的请求方法
87+
* @param method
88+
* @return
89+
*/
90+
public static boolean isPublicMethod(RequestMethod method) {
91+
return method == null || method == GET || method == HEAD;
92+
}
5693
}

‎APIJSON(Server)/APIJSON(Eclipse_JEE)/src/main/java/zuo/biao/apijson/StringUtil.java‎

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -304,15 +304,15 @@ public static boolean isNotEmpty(String s, boolean trim) {
304304

305305
//判断字符类型 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
306306

307-
public static final Pattern alphaPattern;
308-
public static final Pattern bigAlphaPattern;
309-
public static final Pattern namePattern;
310-
public static final Pattern smallAlphaPattern;
307+
public static final Pattern ALPHA_PATTERN;
308+
public static final Pattern NAME_PATTERN;
309+
public static final Pattern BIG_ALPHA_PATTERN;
310+
public static final Pattern SMALL_ALPHA_PATTERN;
311311
static {
312-
alphaPattern = Pattern.compile("[a-zA-Z]");
313-
bigAlphaPattern = Pattern.compile("[A-Z]");
314-
namePattern = Pattern.compile("^[0-9a-zA-Z_]+$");//已用55个中英字符测试通过
315-
smallAlphaPattern = Pattern.compile("[a-z]");
312+
ALPHA_PATTERN = Pattern.compile("[a-zA-Z]");
313+
NAME_PATTERN = Pattern.compile("^[0-9a-zA-Z_]+$");//已用55个中英字符测试通过
314+
BIG_ALPHA_PATTERN = Pattern.compile("[A-Z]");
315+
SMALL_ALPHA_PATTERN = Pattern.compile("[a-z]");
316316
}
317317

318318
//判断手机格式是否正确
@@ -392,6 +392,29 @@ public static boolean isNumberOrAlpha(String s) {
392392
return isNumer(s) || isAlpha(s);
393393
}
394394

395+
/**判断是否为单词,只能包含字母,数字或下划线
396+
* @param s
397+
* @return
398+
*/
399+
public static boolean isWord(String s) {
400+
return s != null && NAME_PATTERN.matcher(s).matches();
401+
}
402+
/**判断是否为首字母大写的单词
403+
* @param key
404+
* @return
405+
*/
406+
public static boolean isBigWord(String s) {
407+
return s != null && BIG_ALPHA_PATTERN.matcher(s.substring(0, 1)).matches() && isWord(s.substring(1));
408+
}
409+
/**判断是否为首字母小写的单词
410+
* @param key
411+
* @return
412+
*/
413+
public static boolean isSmallWord(String s) {
414+
return s != null && SMALL_ALPHA_PATTERN.matcher(s.substring(0, 1)).matches() && isWord(s.substring(1));
415+
}
416+
417+
395418
/**判断字符类型是否是身份证号
396419
* @param idCard
397420
* @return
@@ -722,11 +745,10 @@ public static String[] split(String s, String split) {
722745
* @return key + suffix,第一个字母小写
723746
*/
724747
public static String addSuffix(String key, String suffix) {
725-
key = StringUtil.getNoBlankString(key);
748+
key = getNoBlankString(key);
726749
if (key.isEmpty()) {
727750
return firstCase(suffix);
728751
}
729-
730752
return firstCase(key) + firstCase(suffix, true);
731753
}
732754
/**
@@ -741,7 +763,7 @@ public static String firstCase(String key) {
741763
* @return
742764
*/
743765
public static String firstCase(String key, boolean upper) {
744-
key = StringUtil.getString(key);
766+
key = getString(key);
745767
if (key.isEmpty()) {
746768
return "";
747769
}
@@ -752,7 +774,6 @@ public static String firstCase(String key, boolean upper) {
752774
return key;
753775
}
754776

755-
756777
//校正(自动补全等)字符串>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
757778

758779
}

‎APIJSON(Server)/APIJSON(Eclipse_JEE)/src/main/java/zuo/biao/apijson/server/Logic.java‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,23 @@ public boolean isNot() {
100100
public static boolean isNot(int type) {
101101
return type == TYPE_NOT;
102102
}
103-
103+
104+
public boolean isCorrect() {
105+
return isContain(getType());
106+
}
107+
public static boolean isContain(String s) {
108+
return isContain(getType(s));
109+
}
110+
public static boolean isContain(int type) {
111+
return type >= TYPE_OR && type <= TYPE_NOT;
112+
}
104113

105114
public static int getType(char logicChar) {
106115
return getType(String.valueOf(logicChar));
107116
}
108117
public static int getType(String logicChar) {
109118
int type = -1;
110-
if (logicChar != null && logicChar.isEmpty() == false) {
119+
if (logicChar != null && logicChar.length() == 1) {
111120
if ("|".equals(logicChar)) {
112121
type = 0;
113122
} else if ("&".equals(logicChar)) {

0 commit comments

Comments
 (0)