Skip to content

Commit 050ee40

Browse files
committed
Server:优化批量新增、修改后返回的字段,保持和规范统一;删除 APIJSONBoot 和 APIJSONBootTest 中多余的 apijson-orm 依赖
1 parent 482d885 commit 050ee40

File tree

6 files changed

+14
-14
lines changed

6 files changed

+14
-14
lines changed

APIJSON-Java-Server/APIJSONBoot/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,6 @@
6565
</dependency>
6666
<!-- 没找到合适且稳定的 Oracle 的 JDBC Maven 依赖,已在 libs 目录放了对应的 jar 包来替代 -->
6767

68-
<dependency>
69-
<groupId>com.github.APIJSON</groupId>
70-
<artifactId>apijson-orm</artifactId>
71-
<version>LATEST</version>
72-
</dependency>
7368
<dependency>
7469
<groupId>com.github.APIJSON</groupId>
7570
<artifactId>apijson-framework</artifactId>

APIJSON-Java-Server/APIJSONBoot/src/main/java/apijson/boot/DemoSQLConfig.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@
3030
*/
3131
public class DemoSQLConfig extends APIJSONSQLConfig {
3232

33+
public DemoSQLConfig() {
34+
super();
35+
}
36+
public DemoSQLConfig(RequestMethod method, String table) {
37+
super(method, table);
38+
}
39+
3340
static {
3441
DEFAULT_DATABASE = DATABASE_MYSQL; //TODO 默认数据库类型,改成你自己的
3542
DEFAULT_SCHEMA = "sys"; //TODO 默认模式名,改成你自己的,默认情况是 MySQL: sys, PostgreSQL: public, SQL Server: dbo, Oracle:
@@ -44,7 +51,7 @@ public class DemoSQLConfig extends APIJSONSQLConfig {
4451

4552
@Override
4653
public AbstractSQLConfig getSQLConfig(RequestMethod method, String database, String schema, String table) {
47-
return new APIJSONSQLConfig(method, table);
54+
return new DemoSQLConfig(method, table);
4855
}
4956

5057
//取消注释来实现自定义各个表的主键名
@@ -68,6 +75,7 @@ public String getUserIdKey(String database, String schema, String table) {
6875
};
6976
}
7077

78+
7179
@Override
7280
public String getDBVersion() {
7381
if (isMySQL()) {

APIJSON-Java-Server/APIJSONBootTest/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,6 @@
5555
</dependency>
5656
<!-- 没找到合适且稳定的 Oracle 的 JDBC Maven 依赖,已在 libs 目录放了对应的 jar 包来替代 -->
5757

58-
<dependency>
59-
<groupId>com.github.APIJSON</groupId>
60-
<artifactId>apijson-orm</artifactId>
61-
<version>LATEST</version>
62-
</dependency>
6358
<dependency>
6459
<groupId>com.github.APIJSON</groupId>
6560
<artifactId>apijson-framework</artifactId>

APIJSON-Java-Server/APIJSONBootTest/src/main/java/apijson/boot/test/DemoApplication.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public SQLConfig createSQLConfig() {
4242

4343
public static void main(String[] args) throws Exception {
4444
SpringApplication.run(DemoApplication.class, args);
45+
System.out.println("\n\n<<<<<<<<<<<<<<<<<<<<<<<<< APIJSON 启动完成,试试调用自动化 API 吧 ^_^ >>>>>>>>>>>>>>>>>>>>>>>>\n");
4546
}
4647

4748
}

APIJSON-Java-Server/APIJSONORM/src/main/java/apijson/orm/AbstractObjectParser.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@ public void onTableArrayParse(String key, JSONArray value) throws Exception {
573573
int version = parser.getVersion();
574574
int maxUpdateCount = parser.getMaxUpdateCount();
575575

576+
String idKey = parser.createSQLConfig().getIdKey(); //Table[]: [{}] arrayConfig 为 null
576577
for (int i = 0; i < valueArray.size(); i++) { //只要有一条失败,则抛出异常,全部失败
577578
//TODO 改成一条多 VALUES 的 SQL 性能更高,报错也更会更好处理,更人性化
578579
JSONObject item;
@@ -596,12 +597,12 @@ public void onTableArrayParse(String key, JSONArray value) throws Exception {
596597
}
597598

598599
allCount += count;
599-
ids.add(result.get(JSONResponse.KEY_ID));
600+
ids.add(result.get(idKey));
600601
}
601602

602603
JSONObject allResult = AbstractParser.newSuccessResult();
603-
allResult.put(JSONResponse.KEY_ID_IN, ids);
604604
allResult.put(JSONResponse.KEY_COUNT, allCount);
605+
allResult.put(idKey + "[]", ids);
605606

606607
response.put(key, allResult); //不按原样返回,避免数据量过大
607608
}

APIJSON-Java-Server/APIJSONORM/src/main/java/apijson/orm/AbstractSQLExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,12 @@ public JSONObject execute(@NotNull SQLConfig config, boolean unknowType) throws
222222
, updateCount > 0 ? JSONResponse.MSG_SUCCEED : "没权限访问或对象不存在!");
223223

224224
//id,id{}至少一个会有,一定会返回,不用抛异常来阻止关联写操作时前面错误导致后面无条件执行!
225+
result.put(JSONResponse.KEY_COUNT, updateCount);//返回修改的记录数
225226
if (config.getId() != null) {
226227
result.put(config.getIdKey(), config.getId());
227228
} else {
228229
result.put(config.getIdKey() + "[]", config.getWhere(config.getIdKey() + "{}", true));
229230
}
230-
result.put(JSONResponse.KEY_COUNT, updateCount);//返回修改的记录数
231231
return result;
232232

233233
case GET:

0 commit comments

Comments
 (0)