Skip to content

Commit af89521

Browse files
committed
Java:APIJSONBoot 兼容 MySQL 5.6 及以下等不支持 json 类型的数据库;APIJSONBoot 升级依赖库版本;APIJSONBoot 完善注释和优化代码
1 parent 94f0484 commit af89521

File tree

9 files changed

+80
-53
lines changed

9 files changed

+80
-53
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
APIJSON-Java-Server/APIJSONBoot/.idea

APIJSON-Java-Server/APIJSONBoot/.classpath

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
<attribute name="maven.pomderived" value="true"/>
2828
</attributes>
2929
</classpathentry>
30-
<classpathentry kind="lib" path="libs/apijson-framework-4.3.2.jar"/>
30+
<classpathentry kind="lib" path="libs/apijson-orm-4.2.3.jar"/>
31+
<classpathentry kind="lib" path="libs/unitauto-2.5.0.jar"/>
32+
<classpathentry kind="lib" path="libs/unitauto-jar-2.5.0.jar"/>
33+
<classpathentry kind="lib" path="libs/apijson-framework-4.3.4.jar"/>
3134
<classpathentry kind="output" path="target/classes"/>
3235
</classpath>
Binary file not shown.
Binary file not shown.

APIJSON-Java-Server/APIJSONBoot/pom.xml

Lines changed: 45 additions & 44 deletions
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.0</version>
8+
<version>4.3.4</version>
99
<packaging>jar</packaging>
1010

1111
<name>APIJSONBoot</name>
@@ -25,29 +25,24 @@
2525
</properties>
2626

2727
<dependencies>
28-
<!-- APIJSONORM 需要用的 JSON 封装/解析库,1.2.24 以上 -->
2928
<dependency>
3029
<groupId>com.alibaba</groupId>
3130
<artifactId>fastjson</artifactId>
32-
<version>1.2.73</version>
31+
<version>1.2.74</version>
3332
</dependency>
3433

35-
<!-- APIJSONBoot 需要用的 Spring 框架,1.4.1 以上 -->
36-
<dependency>
37-
<groupId>org.springframework.boot</groupId>
38-
<artifactId>spring-boot-starter</artifactId>
39-
</dependency>
40-
<dependency>
41-
<groupId>org.springframework.boot</groupId>
42-
<artifactId>spring-boot-starter-test</artifactId>
43-
<scope>test</scope>
44-
</dependency>
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+
4538
<dependency>
46-
<groupId>org.springframework.boot</groupId>
47-
<artifactId>spring-boot-starter-web</artifactId>
39+
<groupId>javax.servlet</groupId>
40+
<artifactId>javax.servlet-api</artifactId>
41+
<version>4.0.1</version>
4842
</dependency>
4943

50-
<!-- APIJSONBoot 需要用的数据库 JDBC 驱动 -->
44+
45+
<!-- 数据库 JDBC 驱动 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< -->
5146
<dependency>
5247
<groupId>mysql</groupId>
5348
<artifactId>mysql-connector-java</artifactId>
@@ -63,16 +58,14 @@
6358
<artifactId>jtds</artifactId>
6459
<version>1.3.1</version>
6560
</dependency>
66-
<!-- https://mvnrepository.com/artifact/com.ibm.db2/jcc -->
67-
<dependency>
68-
<groupId>com.ibm.db2</groupId>
69-
<artifactId>jcc</artifactId>
70-
<version>11.5.0.0</version>
71-
</dependency>
7261

7362
<!-- 没找到合适且稳定的 Oracle 的 JDBC Maven 依赖,需要自行下载 jar 包 -->
7463

75-
<!-- 可使用 libs 目录的 unitauto-java.jar 和 unitauto-jar.jar 本地 jar 包依赖来替代,两种方式二选一 -->
64+
<!-- 数据库 JDBC 驱动 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> -->
65+
66+
67+
<!-- 单元测试:可使用 libs 目录的 unitauto-java.jar 和 unitauto-jar.jar 本地 jar 包依赖来替代,两种方式二选一
68+
<<<<<<<<< -->
7669
<dependency>
7770
<groupId>com.github.TommyLemon</groupId>
7871
<artifactId>unitauto-java</artifactId>
@@ -83,19 +76,29 @@
8376
<artifactId>unitauto-jar</artifactId>
8477
<version>2.5.3</version>
8578
</dependency>
79+
<!-- 单元测试:可使用 libs 目录的 unitauto-java.jar 和 unitauto-jar.jar 本地 jar 包依赖来替代,两种方式二选一
80+
>>>>>>>>> -->
81+
8682

8783

88-
<!-- 可使用 libs 目录的 apijson-framework.jar 和 apijson-orm.jar 本地 jar 包依赖来替代,两种方式二选一 -->
89-
<dependency>
90-
<groupId>com.github.APIJSON</groupId>
91-
<artifactId>apijson-orm</artifactId>
92-
<version>4.2.3</version>
84+
<!-- APIJSONBoot 需要用的 Spring 框架,1.4.1 以上 -->
85+
<dependency>
86+
<groupId>org.springframework.boot</groupId>
87+
<artifactId>spring-boot-starter</artifactId>
9388
</dependency>
94-
<!-- <dependency>
95-
<groupId>com.github.APIJSON</groupId>
96-
<artifactId>apijson-framework</artifactId>
97-
<version>4.3.2</version>
98-
</dependency> -->
89+
<dependency>
90+
<groupId>org.springframework.boot</groupId>
91+
<artifactId>spring-boot-starter-test</artifactId>
92+
<scope>test</scope>
93+
</dependency>
94+
<dependency>
95+
<groupId>org.springframework.boot</groupId>
96+
<artifactId>spring-boot-starter-web</artifactId>
97+
</dependency>
98+
99+
<!-- 可使用 libs 目录的 apijson-orm.jar 来替代,两种方式二选一 -->
100+
<!-- <dependency> <groupId>com.github.APIJSON</groupId> <artifactId>apijson-orm</artifactId>
101+
<version>4.2.4</version> </dependency> -->
99102

100103
</dependencies>
101104

@@ -119,24 +122,26 @@
119122
<!-- Allow access to Spring milestones and snapshots -->
120123
<!-- (you don't need this if you are using anything after 0.5.0.RELEASE) -->
121124
<repositories>
125+
<!-- APIJSON 必须用到的托管平台 -->
122126
<repository>
123-
<id>spring-snapshots</id>
124-
<url>http://repo.spring.io/snapshot</url>
127+
<id>jitpack.io</id>
128+
<url>https://jitpack.io</url>
125129
<snapshots>
126130
<enabled>true</enabled>
127131
</snapshots>
128132
</repository>
133+
129134
<repository>
130-
<id>spring-milestones</id>
131-
<url>http://repo.spring.io/milestone</url>
135+
<id>spring-snapshots</id>
136+
<url>http://repo.spring.io/snapshot</url>
132137
<snapshots>
133138
<enabled>true</enabled>
134139
</snapshots>
135140
</repository>
136141
<repository>
137-
<id>jitpack.io</id>
138-
<url>https://jitpack.io</url>
139-
<snapshots>
142+
<id>spring-milestones</id>
143+
<url>http://repo.spring.io/milestone</url>
144+
<snapshots>
140145
<enabled>true</enabled>
141146
</snapshots>
142147
</repository>
@@ -150,10 +155,6 @@
150155
<id>spring-milestones</id>
151156
<url>http://repo.spring.io/milestone</url>
152157
</pluginRepository>
153-
<pluginRepository>
154-
<id>jitpack.io</id>
155-
<url>https://jitpack.io</url>
156-
</pluginRepository>
157158
</pluginRepositories>
158159

159160
</project>

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ public class DemoApplication implements ApplicationContextAware {
6666
private static final String TAG = "DemoApplication";
6767

6868
static {
69-
7069
// APIJSON 配置 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
7170

7271
Map<String, Pattern> COMPILE_MAP = Structure.COMPILE_MAP;
@@ -198,7 +197,7 @@ public static void main(String[] args) throws Exception {
198197
SpringApplication.run(DemoApplication.class, args);
199198

200199
Log.DEBUG = true; //上线生产环境前改为 false,可不输出 APIJSONORM 的日志 以及 SQLException 的原始(敏感)信息
201-
APIJSONApplication.init(true);
200+
APIJSONApplication.init();
202201
}
203202

204203

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,18 @@
2323
public class DemoSQLExecutor extends APIJSONSQLExecutor {
2424
public static final String TAG = "DemoSQLExecutor";
2525

26+
// 可重写以下方法,支持 Redis 等单机全局缓存或分布式缓存
27+
// @Override
28+
// public List<JSONObject> getCache(String sql, int type) {
29+
// return super.getCache(sql, type);
30+
// }
31+
// @Override
32+
// public synchronized void putCache(String sql, List<JSONObject> list, int type) {
33+
// super.putCache(sql, list, type);
34+
// }
35+
// @Override
36+
// public synchronized void removeCache(String sql, int type) {
37+
// super.removeCache(sql, type);
38+
// }
39+
2640
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414

1515
package apijson.boot;
1616

17-
1817
import apijson.framework.APIJSONVerifier;
19-
import apijson.orm.SQLConfig;
2018

2119

2220
/**权限验证器
@@ -25,8 +23,10 @@
2523
public class DemoVerifier extends APIJSONVerifier {
2624
public static final String TAG = "DemoVerifier";
2725

28-
@Override
29-
public String getVisitorIdKey(SQLConfig config) {
30-
return super.getVisitorIdKey(config);
31-
}
26+
// 重写方法来自定义字段名等
27+
// @Override
28+
// public String getVisitorIdKey(SQLConfig config) {
29+
// return super.getVisitorIdKey(config); // return "userid"; // return "uid" 等自定义的字段名
30+
// }
31+
3232
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import java.util.List;
2121

22+
import apijson.JSON;
2223
import apijson.MethodAccess;
2324
import apijson.framework.BaseModel;
2425
import apijson.orm.Visitor;
@@ -83,6 +84,10 @@ public User setPictureList(List<String> pictureList) {
8384
this.pictureList = pictureList;
8485
return this;
8586
}
87+
public User setPictureList(String pictureList) { // 兼容 MySQL 5.6 及以下等不支持 json 类型的数据库
88+
this.pictureList = JSON.parseArray(pictureList, String.class);
89+
return this;
90+
}
8691

8792
public String getTag() {
8893
return tag;
@@ -99,6 +104,10 @@ public User setContactIdList(List<Long> contactIdList) {
99104
this.contactIdList = contactIdList;
100105
return this;
101106
}
107+
public User setContactIdList(String contactIdList) { // 兼容 MySQL 5.6 及以下等不支持 json 类型的数据库
108+
this.contactIdList = JSON.parseArray(contactIdList, Long.class);
109+
return this;
110+
}
102111

103112

104113
}

0 commit comments

Comments
 (0)