Skip to content

Commit 1d2d25f

Browse files
authoredFeb 27, 2020
Merge pull request #119 from zhoulingfengofcd/zhoulingfengofcd-patch-1
Update AbstractObjectParser.java
2 parents 1317a47 + 692c9fc commit 1d2d25f

File tree

2 files changed

+60
-6
lines changed

2 files changed

+60
-6
lines changed
 

‎.gitignore

+32-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,36 @@
11
.DS_Store
2-
.idea
32
.gradle
3+
yarn.lock
4+
*.project
5+
6+
HELP.md
7+
target/
8+
!.mvn/wrapper/maven-wrapper.jar
9+
!**/src/main/**
10+
!**/src/test/**
11+
12+
### STS ###
13+
.apt_generated
14+
.classpath
15+
.factorypath
16+
.project
417
.settings
18+
.springBeans
19+
.sts4-cache
520

6-
yarn.lock
7-
*.classpath
8-
*.project
21+
### IntelliJ IDEA ###
22+
.idea
23+
*.iws
24+
*.iml
25+
*.ipr
26+
27+
### NetBeans ###
28+
/nbproject/private/
29+
/nbbuild/
30+
/dist/
31+
/nbdist/
32+
/.nb-gradle/
33+
build/
34+
35+
### VS Code ###
36+
.vscode/

‎APIJSON-Java-Server/APIJSONORM/src/main/java/zuo/biao/apijson/server/AbstractObjectParser.java

+28-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import static zuo.biao.apijson.JSONObject.KEY_COMBINE;
1818
import static zuo.biao.apijson.JSONObject.KEY_DROP;
1919
import static zuo.biao.apijson.JSONObject.KEY_TRY;
20+
import static zuo.biao.apijson.RequestMethod.POST;
2021
import static zuo.biao.apijson.RequestMethod.PUT;
2122
import static zuo.biao.apijson.server.SQLConfig.TYPE_ITEM;
2223

@@ -240,8 +241,33 @@ public AbstractObjectParser parse() throws Exception {
240241
response.put(key, onChildParse(index, key, (JSONObject)value));
241242
index ++;
242243
}
243-
}
244-
else if (method == PUT && value instanceof JSONArray
244+
} else if (value instanceof JSONArray && method == POST &&
245+
key.startsWith("@") == false && key.endsWith("@") == false) {//JSONArray,批量新增,往下一级提取
246+
JSONArray valueArray = (JSONArray)value;
247+
248+
for (int i = 0; i < valueArray.size(); i++) {
249+
if (childMap != null) {//添加到childMap,最后再解析
250+
childMap.put(key, valueArray.getJSONObject(i));
251+
}
252+
else {//直接解析并替换原来的,[]:{} 内必须直接解析,否则会因为丢掉count等属性,并且total@:"/[]/total"必须在[]:{} 后!
253+
JSONObject result = (JSONObject)onChildParse(index, key, valueArray.getJSONObject(i));
254+
//合并结果
255+
JSONObject before = (JSONObject)response.get(key);
256+
if(result.get("code").equals(200)){
257+
if(before!=null){
258+
before.put("count",before.getInteger("count")+result.getInteger("count"));
259+
response.put(key, before);
260+
}else{
261+
response.put(key, result);
262+
}
263+
} else {
264+
//只要有一条失败,则抛出异常,全部失败
265+
throw new RuntimeException(key + "," + valueArray.getJSONObject(i) +",新增失败!");
266+
}
267+
}
268+
}
269+
index ++;
270+
} else if (method == PUT && value instanceof JSONArray
245271
&& (whereList == null || whereList.contains(key) == false)) {//PUT JSONArray
246272
onPUTArrayParse(key, (JSONArray) value);
247273
}

0 commit comments

Comments
 (0)
Please sign in to comment.