Skip to content

Commit 7251ace

Browse files
committed
Server:同步eclipse版至idea版
1 parent 5977535 commit 7251ace

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

APIJSON-Java-Server/APIJSON-Idea/src/main/java/apijson/demo/server/APIJSONApplication.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,18 @@ public static void main(String[] args) throws Exception {
5757
@Bean
5858
public CorsFilter corsFilter() {
5959
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
60-
source.registerCorsConfiguration("/**", buildConfig()); // 4
60+
source.registerCorsConfiguration("/**", buildConfig());
6161
return new CorsFilter(source);
6262
}
6363
/**CORS跨域配置
6464
* @return
6565
*/
6666
private CorsConfiguration buildConfig() {
6767
CorsConfiguration corsConfiguration = new CorsConfiguration();
68-
corsConfiguration.addAllowedOrigin("*");
69-
corsConfiguration.addAllowedHeader("*");
70-
corsConfiguration.addAllowedMethod("*");
68+
corsConfiguration.addAllowedOrigin("*"); //允许的域名或IP地址
69+
corsConfiguration.addAllowedHeader("*"); //允许的请求头
70+
corsConfiguration.addAllowedMethod("*"); //允许的HTTP请求方法
71+
corsConfiguration.setAllowCredentials(true); //允许发送跨域凭据,前端Axios存取JSESSIONID必须要
7172
return corsConfiguration;
7273
}
7374
//支持JavaScript跨域请求 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

APIJSON-Java-Server/APIJSON-Idea/src/main/java/zuo/biao/apijson/JSONRequest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public JSONRequest(String name, Object object) {
5151

5252

5353
public static final String KEY_TAG = "tag";//只在最外层,最外层用JSONRequest
54+
public static final String KEY_VERSION = "version";//只在最外层,最外层用JSONRequest
5455

5556
/**set "tag":tag in outermost layer
5657
* for write operations
@@ -60,6 +61,14 @@ public JSONRequest(String name, Object object) {
6061
public JSONRequest setTag(String tag) {
6162
return puts(KEY_TAG, tag);
6263
}
64+
/**set "version":version in outermost layer
65+
* for target version of request
66+
* @param version
67+
* @return
68+
*/
69+
public JSONRequest setVersion(String version) {
70+
return puts(KEY_VERSION, version);
71+
}
6372

6473

6574
//array object <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

APIJSON-Java-Server/APIJSON-Idea/src/main/java/zuo/biao/apijson/server/Parser.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,11 +374,12 @@ public static JSONObject getCorrectRequest(@NotNull RequestMethod method, JSONOb
374374
if (StringUtil.isNotEmpty(tag, true) == false) {
375375
throw new IllegalArgumentException("请设置tag!一般是Table名");
376376
}
377+
int version = request.getIntValue(JSONRequest.KEY_VERSION);
377378

378379
JSONObject object = null;
379380
String error = "";
380381
try {
381-
object = getStructure(method, "Request", JSONRequest.KEY_TAG, tag);
382+
object = getStructure(method, "Request", JSONRequest.KEY_TAG, tag, version);
382383
} catch (Exception e) {
383384
error = e.getMessage();
384385
}
@@ -396,6 +397,7 @@ public static JSONObject getCorrectRequest(@NotNull RequestMethod method, JSONOb
396397
//获取指定的JSON结构 >>>>>>>>>>>>>>
397398

398399
request.remove(JSONRequest.KEY_TAG);
400+
request.remove(JSONRequest.KEY_VERSION);
399401
return Structure.parseRequest(method, "", (JSONObject) target.clone(), request);
400402
}
401403

@@ -431,11 +433,12 @@ public static JSONObject getCorrectResponse(@NotNull final RequestMethod method
431433
* @param table
432434
* @param key
433435
* @param value
436+
* @param version
434437
* @return
435438
* @throws Exception
436439
*/
437440
public static JSONObject getStructure(@NotNull final RequestMethod method, @NotNull String table,
438-
String key, String value) throws Exception {
441+
String key, String value, int version) throws Exception {
439442
//获取指定的JSON结构 <<<<<<<<<<<<<<
440443
SQLConfig config = new SQLConfig(GET, table);
441444
config.setColumn("structure");
@@ -445,7 +448,12 @@ public static JSONObject getStructure(@NotNull final RequestMethod method, @NotN
445448
if (key != null) {
446449
where.put(key, value);
447450
}
451+
if (version > 0) {
452+
where.put(JSONRequest.KEY_VERSION + "{}", ">=" + version);
453+
}
448454
config.setWhere(where);
455+
config.setOrder(JSONRequest.KEY_VERSION + (version > 0 ? "+" : "-"));
456+
config.setCount(1);
449457

450458
SQLExecutor qh = new SQLExecutor();
451459

APIJSON-Java-Server/APIJSON-Idea/src/test/java/zuo/biao/apijson/server/ApplicationTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public class ApplicationTests {
1111

1212
@Test
1313
public void contextLoads() {
14+
//TODO Test Case,包括GitHub README介绍和简版demo
1415
}
1516

1617
}

0 commit comments

Comments
 (0)