Skip to content

Commit fd91f26

Browse files
committed
Java:APIJSONBoot 迁移部分与 SpringBoot 不耦合的类到 apijson.demo 目录;APIJSONBoot 优化 pom.xml
1 parent a1f8933 commit fd91f26

17 files changed

+974
-20
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
11
APIJSON-Java-Server/APIJSONBoot/.idea
2+
.classpath
3+
.project
4+
APIJSON-Java-Server/APIJSONBoot/.settings
5+
APIJSON-Java-Server/APIJSONBootTest/.settings
6+
APIJSON-Java-Server/APIJSONFinal/.settings
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target/

APIJSON-Java-Server/APIJSONBoot/pom.xml

+16-16
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>apijson.boot</groupId>
77
<artifactId>apijson-boot</artifactId>
8-
<version>4.3.4</version>
8+
<version>4.4.0</version>
99
<packaging>jar</packaging>
1010

1111
<name>APIJSONBoot</name>
@@ -31,16 +31,24 @@
3131
<version>1.2.74</version>
3232
</dependency>
3333

34-
<!-- 可使用 libs 目录的 apijson-framework.jar 和 apijson-orm.jar 等本地 jar 包依赖来替代,两种方式二选一 -->
35-
<!-- <dependency> <groupId>com.github.APIJSON</groupId> <artifactId>apijson-framework</artifactId>
36-
<version>4.3.4</version> </dependency> -->
37-
3834
<dependency>
3935
<groupId>javax.servlet</groupId>
4036
<artifactId>javax.servlet-api</artifactId>
4137
<version>4.0.1</version>
4238
</dependency>
4339

40+
<!-- 可使用 libs 目录的 apijson-orm.jar 和 apijson-framework.jar 来替代,两种方式二选一 <<<<<<<<<< -->
41+
<dependency>
42+
<groupId>com.github.Tencent</groupId>
43+
<artifactId>APIJSON</artifactId>
44+
<version>4.2.4</version>
45+
</dependency>
46+
<dependency>
47+
<groupId>com.github.APIJSON</groupId>
48+
<artifactId>apijson-framework</artifactId>
49+
<version>4.3.3</version>
50+
</dependency>
51+
<!-- 可使用 libs 目录的 apijson-orm.jar 和 apijson-framework.jar 来替代,两种方式二选一 >>>>>>>>>> -->
4452

4553
<!-- 数据库 JDBC 驱动 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< -->
4654
<dependency>
@@ -58,14 +66,11 @@
5866
<artifactId>jtds</artifactId>
5967
<version>1.3.1</version>
6068
</dependency>
61-
6269
<!-- 没找到合适且稳定的 Oracle 的 JDBC Maven 依赖,需要自行下载 jar 包 -->
63-
6470
<!-- 数据库 JDBC 驱动 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> -->
6571

6672

67-
<!-- 单元测试:可使用 libs 目录的 unitauto-java.jar 和 unitauto-jar.jar 本地 jar 包依赖来替代,两种方式二选一
68-
<<<<<<<<< -->
73+
<!-- 单元测试:可使用 libs 目录的 unitauto-java.jar 和 unitauto-jar.jar 来替代,两种方式二选一 <<<<<<<<< -->
6974
<dependency>
7075
<groupId>com.github.TommyLemon</groupId>
7176
<artifactId>unitauto-java</artifactId>
@@ -76,12 +81,11 @@
7681
<artifactId>unitauto-jar</artifactId>
7782
<version>2.5.3</version>
7883
</dependency>
79-
<!-- 单元测试:可使用 libs 目录的 unitauto-java.jar 和 unitauto-jar.jar 本地 jar 包依赖来替代,两种方式二选一
80-
>>>>>>>>> -->
84+
<!-- 单元测试:可使用 libs 目录的 unitauto-java.jar 和 unitauto-jar.jar 来替代,两种方式二选一 >>>>>>>>> -->
8185

8286

8387

84-
<!-- APIJSONBoot 需要用的 Spring 框架,1.4.1 以上 -->
88+
<!-- APIJSONBoot 需要用的 SpringBoot 框架,1.4.1 以上 -->
8589
<dependency>
8690
<groupId>org.springframework.boot</groupId>
8791
<artifactId>spring-boot-starter</artifactId>
@@ -96,10 +100,6 @@
96100
<artifactId>spring-boot-starter-web</artifactId>
97101
</dependency>
98102

99-
<!-- 可使用 libs 目录的 apijson-orm.jar 来替代,两种方式二选一 -->
100-
<!-- <dependency> <groupId>com.github.APIJSON</groupId> <artifactId>apijson-orm</artifactId>
101-
<version>4.2.4</version> </dependency> -->
102-
103103
</dependencies>
104104

105105
<build>

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

+5
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040

4141
import apijson.Log;
4242
import apijson.StringUtil;
43+
import apijson.demo.DemoFunctionParser;
44+
import apijson.demo.DemoParser;
45+
import apijson.demo.DemoSQLConfig;
46+
import apijson.demo.DemoSQLExecutor;
47+
import apijson.demo.DemoVerifier;
4348
import apijson.framework.APIJSONApplication;
4449
import apijson.framework.APIJSONCreator;
4550
import apijson.orm.FunctionParser;

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,12 @@
7171
import apijson.Log;
7272
import apijson.RequestMethod;
7373
import apijson.StringUtil;
74-
import apijson.boot.model.Privacy;
75-
import apijson.boot.model.User;
76-
import apijson.boot.model.Verify;
74+
import apijson.demo.DemoFunctionParser;
75+
import apijson.demo.DemoParser;
76+
import apijson.demo.DemoVerifier;
77+
import apijson.demo.model.Privacy;
78+
import apijson.demo.model.User;
79+
import apijson.demo.model.Verify;
7780
import apijson.framework.APIJSONController;
7881
import apijson.framework.BaseModel;
7982
import apijson.framework.StructureUtil;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* 示例服务端工程包
2+
* 示例服务端关于 SpingBoot 配置的工程包
33
*/
44
/**
55
* @author Lemon
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
/*Copyright ©2016 TommyLemon(https://github.com/TommyLemon/APIJSON)
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.*/
14+
15+
package apijson.demo;
16+
17+
import java.util.ArrayList;
18+
import java.util.Arrays;
19+
import java.util.Collection;
20+
21+
import javax.servlet.http.HttpSession;
22+
23+
import com.alibaba.fastjson.JSONArray;
24+
import com.alibaba.fastjson.JSONObject;
25+
26+
import apijson.JSONResponse;
27+
import apijson.NotNull;
28+
import apijson.RequestMethod;
29+
import apijson.RequestRole;
30+
import apijson.StringUtil;
31+
import apijson.framework.APIJSONFunctionParser;
32+
import apijson.orm.JSONRequest;
33+
34+
35+
/**可远程调用的函数类
36+
* @author Lemon
37+
*/
38+
public class DemoFunctionParser extends APIJSONFunctionParser {
39+
public static final String TAG = "DemoFunctionParser";
40+
41+
public DemoFunctionParser() {
42+
this(null, null, 0, null, null);
43+
}
44+
public DemoFunctionParser(RequestMethod method, String tag, int version, JSONObject request, HttpSession session) {
45+
super(method, tag, version, request, session);
46+
}
47+
48+
/**
49+
* @param current
50+
* @return
51+
* @throws Exception
52+
*/
53+
public Object verifyIdList(@NotNull JSONObject current, @NotNull String idList) throws Exception {
54+
Object obj = current.get(idList);
55+
if (obj instanceof Collection == false) {
56+
throw new IllegalArgumentException(idList + " 不符合 Array 类型! 结构必须是 [] !");
57+
}
58+
JSONArray array = (JSONArray) obj;
59+
if (array != null) {
60+
for (int i = 0; i < array.size(); i++) {
61+
if (array.get(i) instanceof Long == false && array.get(i) instanceof Integer == false) {
62+
throw new IllegalArgumentException(idList + " 内字符 " + array.getString(i) + " 不符合 Long 类型!");
63+
}
64+
}
65+
}
66+
return null;
67+
}
68+
69+
70+
/**
71+
* @param request
72+
* @return
73+
* @throws Exception
74+
*/
75+
public Object verifyURLList(@NotNull JSONObject current, @NotNull String urlList) throws Exception {
76+
Object obj = current.get(urlList);
77+
if (obj instanceof Collection == false) {
78+
throw new IllegalArgumentException(urlList + " 不符合 Array 类型! 结构必须是 [] !");
79+
}
80+
JSONArray array = (JSONArray) obj;
81+
if (array != null) {
82+
for (int i = 0; i < array.size(); i++) {
83+
if (StringUtil.isUrl(array.getString(i)) == false) {
84+
throw new IllegalArgumentException(urlList + " 内字符 " + array.getString(i) + " 不符合 URL 格式!");
85+
}
86+
}
87+
}
88+
return null;
89+
}
90+
91+
92+
/**
93+
* @param rq
94+
* @param momentId
95+
* @return
96+
* @throws Exception
97+
*/
98+
public int deleteCommentOfMoment(@NotNull JSONObject current, @NotNull String momentId) throws Exception {
99+
long mid = current.getLongValue(momentId);
100+
if (mid <= 0 || current.getIntValue(JSONResponse.KEY_COUNT) <= 0) {
101+
return 0;
102+
}
103+
104+
JSONRequest request = new JSONRequest();
105+
106+
//Comment<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
107+
JSONRequest comment = new JSONRequest();
108+
comment.put("momentId", mid);
109+
110+
request.put("Comment", comment);
111+
//Comment>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
112+
113+
JSONObject rp = new DemoParser(RequestMethod.DELETE).setNeedVerify(false).parseResponse(request);
114+
115+
JSONObject c = rp.getJSONObject("Comment");
116+
return c == null ? 0 : c.getIntValue(JSONResponse.KEY_COUNT);
117+
}
118+
119+
120+
/**删除评论的子评论
121+
* @param rq
122+
* @param toId
123+
* @return
124+
*/
125+
public int deleteChildComment(@NotNull JSONObject current, @NotNull String toId) throws Exception {
126+
long tid = current.getLongValue(toId);
127+
if (tid <= 0 || current.getIntValue(JSONResponse.KEY_COUNT) <= 0) {
128+
return 0;
129+
}
130+
131+
//递归获取到全部子评论id
132+
133+
JSONRequest request = new JSONRequest();
134+
135+
//Comment<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
136+
JSONRequest comment = new JSONRequest();
137+
comment.put("id{}", getChildCommentIdList(tid));
138+
139+
request.put("Comment", comment);
140+
//Comment>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
141+
142+
JSONObject rp = new DemoParser(RequestMethod.DELETE).setNeedVerify(false).parseResponse(request);
143+
144+
JSONObject c = rp.getJSONObject("Comment");
145+
return c == null ? 0 : c.getIntValue(JSONResponse.KEY_COUNT);
146+
}
147+
148+
149+
private JSONArray getChildCommentIdList(long tid) {
150+
151+
JSONArray arr = new JSONArray();
152+
153+
JSONRequest request = new JSONRequest();
154+
155+
//Comment-id[]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
156+
JSONRequest idItem = new JSONRequest();
157+
158+
//Comment<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
159+
JSONRequest comment = new JSONRequest();
160+
comment.put("toId", tid);
161+
comment.setColumn("id");
162+
idItem.put("Comment", comment);
163+
//Comment>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
164+
165+
request.putAll(idItem.toArray(0, 0, "Comment-id"));
166+
//Comment-id[]>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
167+
168+
JSONObject rp = new DemoParser().setNeedVerify(false).parseResponse(request);
169+
170+
JSONArray a = rp.getJSONArray("Comment-id[]");
171+
if (a != null) {
172+
arr.addAll(a);
173+
174+
JSONArray a2;
175+
for (int i = 0; i < a.size(); i++) {
176+
177+
a2 = getChildCommentIdList(a.getLongValue(i));
178+
if (a2 != null) {
179+
arr.addAll(a2);
180+
}
181+
}
182+
}
183+
184+
return arr;
185+
}
186+
187+
188+
/**TODO 仅用来测试 "key-()":"getIdList()" 和 "key()":"getIdList()"
189+
* @param request
190+
* @return JSONArray 只能用JSONArray,用long[]会在SQLConfig解析崩溃
191+
* @throws Exception
192+
*/
193+
public JSONArray getIdList(@NotNull JSONObject current) {
194+
return new JSONArray(new ArrayList<Object>(Arrays.asList(12, 15, 301, 82001, 82002, 38710)));
195+
}
196+
197+
198+
/**TODO 仅用来测试 "key-()":"verifyAccess()"
199+
* @param request
200+
* @return
201+
* @throws Exception
202+
*/
203+
public Object verifyAccess(@NotNull JSONObject current) throws Exception {
204+
long userId = current.getLongValue(JSONRequest.KEY_USER_ID);
205+
RequestRole role = RequestRole.get(current.getString(JSONRequest.KEY_ROLE));
206+
if (role == RequestRole.OWNER && userId != DemoVerifier.getVisitorId(getSession())) {
207+
throw new IllegalAccessException("登录用户与角色OWNER不匹配!");
208+
}
209+
return null;
210+
}
211+
212+
213+
214+
215+
}

0 commit comments

Comments
 (0)