Skip to content

Commit 608d680

Browse files
committed
优化字段,JSONObject内关键字标为@key
1 parent de90405 commit 608d680

5 files changed

Lines changed: 15 additions & 15 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public JSONObject add(com.alibaba.fastjson.JSONObject object) {
8080
* @return
8181
*/
8282
public static boolean isArrayKey(String key) {
83-
return key != null && key.endsWith("[]");
83+
return key != null && key.endsWith(KEY_ARRAY);
8484
}
8585
/**判断是否为对应Table的key
8686
* @param key

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public JSONRequest(String name, Object object) {
3838

3939

4040

41-
public static final String KEY_TAG = "tag";
42-
public static final String KEY_COLUMNS = "columns";
41+
public static final String KEY_TAG = "tag";//放最外层及[]里的不会和其它字段冲突
42+
public static final String KEY_COLUMNS = "@columns";//只有放在请求table的Object里的关键字才用@key形式
4343
/**set tag
4444
* @param tag
4545
* @return

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ private JSONObject newRequest(JSONObject object, String name, boolean needTag) {
293293
JSONObject request = new JSONObject(true);
294294
request.put(name, object);
295295
if (needTag) {
296-
request.put("tag", name);
296+
request.put(JSONRequest.KEY_TAG, name);
297297
}
298298
return request;
299299
}

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.alibaba.fastjson.JSONArray;
2323
import com.alibaba.fastjson.JSONObject;
2424

25+
import zuo.biao.apijson.JSONRequest;
2526
import zuo.biao.apijson.RequestMethod;
2627
import zuo.biao.apijson.StringUtil;
2728
import zuo.biao.apijson.Table;
@@ -32,8 +33,6 @@
3233
public class QueryConfig {
3334
private static final String TAG = "QueryConfig";
3435

35-
public static final String KEY_COLUMNS = "columns";
36-
3736
private long id;
3837
private RequestMethod method;
3938
private String table;
@@ -216,7 +215,7 @@ public static String getWhereString(RequestMethod method, Map<String, Object> wh
216215
Log.d(TAG, "getWhereString key = " + key);
217216
//避免筛选到全部 value = key == null ? null : where.get(key);
218217
if (key == null || key.startsWith("@") || key.endsWith("()")) {//关键字||方法
219-
Log.d(TAG, "getWhereString key.startsWith(@) >> continue;");
218+
Log.d(TAG, "getWhereString key == null || key.startsWith(@) || key.endsWith(()) >> continue;");
220219
continue;
221220
}
222221
if (key.endsWith("@")) {//引用
@@ -311,7 +310,7 @@ public static synchronized QueryConfig newQueryConfig(RequestMethod method, Stri
311310

312311
Set<String> set = request == null ? null : request.keySet();
313312
if (set != null) {
314-
String columns = request.getString(KEY_COLUMNS);
313+
String columns = request.getString(JSONRequest.KEY_COLUMNS);
315314
if (method == RequestMethod.POST) {
316315
config.setColumns(StringUtil.getString(set.toArray(new String[]{})));
317316
String valuesString = "";
@@ -324,7 +323,7 @@ public static synchronized QueryConfig newQueryConfig(RequestMethod method, Stri
324323
}
325324
config.setValues("(" + valuesString + ")");
326325
} else {
327-
request.remove(KEY_COLUMNS);
326+
request.remove(JSONRequest.KEY_COLUMNS);
328327

329328
Map<String, Object> transferredRequest = new HashMap<String, Object>();
330329
Object value;

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.alibaba.fastjson.JSONObject;
2929

3030
import zuo.biao.apijson.JSON;
31+
import zuo.biao.apijson.JSONRequest;
3132
import zuo.biao.apijson.RequestMethod;
3233
import zuo.biao.apijson.StringUtil;
3334
import zuo.biao.apijson.Table;
@@ -141,7 +142,7 @@ public static JSONObject parseRequest(String request, RequestMethod method) {
141142
method = RequestMethod.GET;
142143
}
143144
System.out.println("\n\n\n\n<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n " + TAG + method.name()
144-
+ "/parseResponse request = " + request);
145+
+ "/parseResponse request = \n" + request);
145146
return JSON.parseObject(request);
146147
}
147148

@@ -234,7 +235,7 @@ public static JSONObject getCorrectRequest(RequestMethod method, JSONObject requ
234235
return request;//需要指定JSON结构的get请求可以改为post请求。一般只有对安全性要求高的才会指定,而这种情况用明文的GET方式几乎肯定不安全
235236
}
236237

237-
String tag = request.getString("tag");
238+
String tag = request.getString(JSONRequest.KEY_TAG);
238239
if (StringUtil.isNotEmpty(tag, true) == false) {
239240
throw new IllegalArgumentException("请指定tag!一般是table名称");
240241
}
@@ -245,7 +246,7 @@ public static JSONObject getCorrectRequest(RequestMethod method, JSONObject requ
245246

246247
Map<String, Object> where = new HashMap<String, Object>();
247248
where.put("method", method.name());
248-
where.put("tag", tag);
249+
where.put(JSONRequest.KEY_TAG, tag);
249250
config.setWhere(where);
250251

251252
JSONObject object = null;
@@ -270,7 +271,7 @@ public static JSONObject getCorrectRequest(RequestMethod method, JSONObject requ
270271
}
271272
//获取指定的JSON结构 >>>>>>>>>>>>>>
272273

273-
request.remove("tag");
274+
request.remove(JSONRequest.KEY_TAG);
274275
return fillTarget(method, target, request, "");
275276
}
276277

@@ -534,8 +535,8 @@ private JSONObject getArray(String parentPath, QueryConfig parentConfig, String
534535

535536
int page = 0, count = 0;
536537
try {
537-
page = request.getIntValue("page");
538-
count = request.getIntValue("count");
538+
page = request.getIntValue(JSONRequest.KEY_PAGE);
539+
count = request.getIntValue(JSONRequest.KEY_COUNT);
539540
} catch (Exception e) {
540541
System.out.println(TAG + "getArray try { page = arrayObject.getIntValue(page); ..." +
541542
" >> } catch (Exception e) {\n" + e.getMessage());

0 commit comments

Comments
 (0)