8000 Server:新增支持登录时传全局默认 格式化[]等特殊字符的配置 format:Boolean · coder-caicai/APIJSON@4cd9e7e · GitHub
[go: up one dir, main page]

Skip to content

Commit 4cd9e7e

Browse files
committed
Server:新增支持登录时传全局默认 格式化[]等特殊字符的配置 format:Boolean
1 parent e482237 commit 4cd9e7e

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

APIJSON-Java-Server/APIJSONDemo/src/main/java/apijson/demo/server/Controller.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ public String openHead(@PathVariable String request, HttpSession session) {
213213
}
214214

215215
public static final String VERSION = JSONRequest.KEY_VERSION;
216+
public static final String FORMAT = JSONRequest.KEY_FORMAT;
216217
public static final String COUNT = JSONResponse.KEY_COUNT;
217218
public static final String TOTAL = JSONResponse.KEY_TOTAL;
218219

@@ -419,6 +420,7 @@ public JSONObject login(@RequestBody String request, HttpSession session) {
419420
String phone;
420421
String password;
421422
int version;
423+
Boolean format;
422424
try {
423425
requestObject = DemoParser.parseRequest(request);
424426

@@ -440,9 +442,11 @@ public JSONObject login(@RequestBody String request, HttpSession session) {
440442
}
441443
}
442444

443-
//全局版本号
445+
//全局版本号,是否格式化
444446
version = requestObject.getIntValue(VERSION);
447+
format = requestObject.getBoolean(FORMAT);
445448
requestObject.remove(VERSION);
449+
requestObject.remove(FORMAT);
446450
} catch (Exception e) {
447451
return DemoParser.extendErrorResult(requestObject, e);
448452
}
@@ -511,6 +515,7 @@ public JSONObject login(@RequestBody String request, HttpSession session) {
511515
session.setAttribute(USER_, user);//用户
512516
session.setAttribute(PRIVACY_, privacy);//用户隐私信息
513517
session.setAttribute(VERSION, version);//全局默认版本号
518+
session.setAttribute(FORMAT, format);//全局默认格式化配置
514519
// session.setMaxInactiveInterval(1*60);//设置session过期时间
515520

516521
return response;

APIJSON-Java-Server/APIJSONDemo/src/main/java/apijson/demo/server/DemoParser.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,17 @@ public SQLConfig createSQLConfig() {
6767
public SQLExecutor createSQLExecutor() {
6868
return new DemoSQLExecutor();
6969
}
70-
71-
72-
70+
71+
@Override
72+
public JSONObject parseResponse(JSONObject request) {
73+
//补充format
74+
if (session != null && request != null && request.get(JSONRequest.KEY_FORMAT) == null) {
75+
request.put(JSONRequest.KEY_FORMAT, session.getAttribute(JSONRequest.KEY_FORMAT));
76+
}
77+
return super.parseResponse(request);
78+
}
79+
80+
7381
@Override
7482
public DemoObjectParser createObjectParser(JSONObject request, String parentPath, String name, SQLConfig arrayConfig) throws Exception {
7583

@@ -106,12 +114,12 @@ public JSONObject parseResponse(JSONRequest request) throws Exception {
106114
}.setMethod(requestMethod).setParser(this);
107115
}
108116

109-
110-
117+
118+
111119
@Override
112120
protected void onVerifyContent() throws Exception {
113-
//补充全局缺省版本号
114-
if (session != null && requestObject.getIntValue(JSONRequest.KEY_VERSION) <= 0) {
121+
//补充全局缺省版本号 //可能在默认为1的前提下这个请求version就需要为0 requestObject.getIntValue(JSONRequest.KEY_VERSION) <= 0) {
122+
if (session != null && requestObject.get(JSONRequest.KEY_VERSION) == null) {
115123
requestObject.put(JSONRequest.KEY_VERSION, session.getAttribute(JSONRequest.KEY_VERSION));
116124
}
117125
super.onVerifyContent();

0 commit comments

Comments
 (0)
0