Skip to content

Commit de1f1af

Browse files
committed
Server:支持自定义 post 插入数据的 id,可为 Long 或 String 类型
1 parent 1edf5e4 commit de1f1af

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ public static SQLConfig newSQLConfig(RequestMethod method, String table, JSONObj
8787
public DemoSQLConfig getSQLConfig(RequestMethod method, String table) {
8888
return new DemoSQLConfig(method, table);
8989
}
90+
91+
@Override
92+
public Object newId(RequestMethod method, String table) {
93+
return System.currentTimeMillis(); //为 post 请求提供 id, 只能是 Long 或 String
94+
}
9095
});
9196
}
9297

APIJSON-Java-Server/APIJSONLibrary/src/main/java/zuo/biao/apijson/server/AbstractSQLConfig.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1767,7 +1767,7 @@ public static AbstractSQLConfig newSQLConfig(RequestMethod method, String table,
17671767
throw new IllegalArgumentException("POST请求,生成多条记录请用 id{}:[] ! [] 类型为JSONArray且不能为空!");
17681768
}
17691769
} else if (request.get(KEY_ID) == null) {
1770-
request.put(KEY_ID, System.currentTimeMillis());
1770+
request.put(KEY_ID, callback.newId(method, table));
17711771
}
17721772
}
17731773

@@ -2156,7 +2156,19 @@ else if (key.endsWith("-")) {//缩减,PUT查询时处理
21562156

21572157

21582158
public interface Callback {
2159+
/**获取 SQLConfig 的实例
2160+
* @param method
2161+
* @param table
2162+
* @return
2163+
*/
21592164
AbstractSQLConfig getSQLConfig(RequestMethod method, String table);
2165+
2166+
/**为 post 请求新建 id, 只能是 Long 或 String
2167+
* @param method
2168+
* @param table
2169+
* @return
2170+
*/
2171+
Object newId(RequestMethod method, String table);
21602172
}
21612173

21622174
}

0 commit comments

Comments
 (0)