Skip to content

Commit b3dbb58

Browse files
committed
Java:APIJSONBootTest 重命名为 APIJSONDemo; APIJSONFinal 中 AppRunnableConfig 重命名为 DemoAppConfig;升级 APIJSONORM 和 apijson-framework 的版本;完善使用文档;
1 parent d5f3200 commit b3dbb58

File tree

25 files changed

+129
-80
lines changed

25 files changed

+129
-80
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ APIJSON-Java-Server/APIJSONBootTest/.settings
66
APIJSON-Java-Server/APIJSONFinal/.settings
77
APIJSON-Java-Server/APIJSONFinal/.idea
88
apijson-final.iml
9+
APIJSON-Java-Server/APIJSONDemo/.settings
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# APIJSONBoot
2+
3+
APIJSON + SpringBoot 接近成品的 Demo
4+
5+
### 运行
6+
7+
右键 DemoApplication > Run As > Java Application
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

APIJSON-Java-Server/APIJSONBoot/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@
3838
</dependency>
3939

4040
<!-- 可使用 libs 目录的 apijson-orm.jar 和 apijson-framework.jar 来替代,两种方式二选一 <<<<<<<<<< -->
41-
<dependency>
41+
<dependency>
4242
<groupId>com.github.Tencent</groupId>
4343
<artifactId>APIJSON</artifactId>
44-
<version>4.2.4</version>
44+
<version>4.2.5</version>
4545
</dependency>
4646
<dependency>
4747
<groupId>com.github.APIJSON</groupId>
4848
<artifactId>apijson-framework</artifactId>
49-
<version>4.4.0</version>
49+
<version>4.4.3</version>
5050
</dependency>
5151
<!-- 可使用 libs 目录的 apijson-orm.jar 和 apijson-framework.jar 来替代,两种方式二选一 >>>>>>>>>> -->
5252

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

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,13 @@ public DemoSQLConfig(RequestMethod method, String table) {
4141
DEFAULT_DATABASE = DATABASE_MYSQL; //TODO 默认数据库类型,改成你自己的
4242
DEFAULT_SCHEMA = "sys"; //TODO 默认模式名,改成你自己的,默认情况是 MySQL: sys, PostgreSQL: public, SQL Server: dbo, Oracle:
4343

44-
// 由 DemoVerifier.init 方法读取数据库 Access 表来替代手动输入配置
45-
// //表名映射,隐藏真实表名,对安全要求很高的表可以这么做
44+
//表名和数据库不一致的,需要配置映射关系。只使用 APIJSONORM 时才需要;
45+
//这个 Demo 用了 apijson-framework 且调用了 APIJSONApplication.init
46+
//(间接调用 DemoVerifier.init 方法读取数据库 Access 表来替代手动输入配置),所以不需要。
47+
//但如果 Access 这张表的对外表名与数据库实际表名不一致,仍然需要这里注册。例如
48+
// TABLE_KEY_MAP.put(Access.class.getSimpleName(), "access");
49+
50+
//表名映射,隐藏真实表名,对安全要求很高的表可以这么做
4651
// TABLE_KEY_MAP.put(User.class.getSimpleName(), "apijson_user");
4752
// TABLE_KEY_MAP.put(Privacy.class.getSimpleName(), "apijson_privacy");
4853

@@ -72,11 +77,11 @@ public String getUserIdKey(String database, String schema, String table) {
7277
// public Object newId(RequestMethod method, String database, String schema, String table) {
7378
// return null; // return null 则不生成 id,一般用于数据库自增 id
7479
// }
75-
76-
// @Override
77-
// public void onMissingKey4Combine(String name, JSONObject request, String combine, String item, String key) throws Exception {
78-
//// super.onMissingKey4Combine(name, request, combine, item, key);
79-
// }
80+
81+
// @Override
82+
// public void onMissingKey4Combine(String name, JSONObject request, String combine, String item, String key) throws Exception {
83+
//// super.onMissingKey4Combine(name, request, combine, item, key);
84+
// }
8085
};
8186

8287
// 自定义where条件拼接
@@ -161,7 +166,13 @@ public String getDBPassword() {
161166
}
162167
return null;
163168
}
164-
169+
170+
//取消注释后,默认的 APIJSON 配置表会由业务表所在数据库模式 schema 改为自定义的
171+
// @Override
172+
// public String getConfigSchema() {
173+
// return "apijson";
174+
// }
175+
165176
//取消注释后,默认的数据库类型会由 MySQL 改为 PostgreSQL
166177
// @Override
167178
// public String getDatabase() {

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

Lines changed: 0 additions & 52 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# APIJSONDemo
2+
3+
APIJSON + SpringBoot 初级使用的最简单 Demo
4+
5+
### 运行
6+
7+
右键 DemoApplication > Run As > Java Application

APIJSON-Java-Server/APIJSONBootTest/pom.xml renamed to APIJSON-Java-Server/APIJSONDemo/pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
44
<modelVersion>4.0.0</modelVersion>
55

6-
<groupId>apijson.boot.test</groupId>
7-
<artifactId>apijson-boot-test</artifactId>
6+
<groupId>apijson.demo</groupId>
7+
<artifactId>apijson-demo</artifactId>
88
<version>4.0.0</version>
99
<packaging>jar</packaging>
1010

11-
<name>APIJSONBootTest</name>
11+
<name>APIJSONDemo</name>
1212
<description>Demo project for Testing APIJSON Server based on SpringBoot</description>
1313

1414
<parent>
@@ -29,7 +29,7 @@
2929
<dependency>
3030
<groupId>com.alibaba</groupId>
3131
<artifactId>fastjson</artifactId>
32-
<version>1.2.73</version>
32+
<version>1.2.74</version>
3333
</dependency>
3434

3535
<!-- APIJSONBoot 需要用的 Spring 框架,1.4.1 以上 -->

APIJSON-Java-Server/APIJSONBootTest/src/main/java/apijson/boot/test/DemoApplication.java renamed to APIJSON-Java-Server/APIJSONDemo/src/main/java/apijson/demo/DemoApplication.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
See the License for the specific language governing permissions and
1313
limitations under the License.*/
1414

15-
package apijson.boot.test;
15+
package apijson.demo;
1616

1717
import org.springframework.boot.SpringApplication;
1818
import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -42,7 +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");
45+
APIJSONApplication.init(false); // 4.4.0 以上需要这句来保证以上 static 代码块中给 DEFAULT_APIJSON_CREATOR 赋值会生效
4646
}
4747

4848
}

APIJSON-Java-Server/APIJSONBootTest/src/main/java/apijson/boot/test/DemoController.java renamed to APIJSON-Java-Server/APIJSONDemo/src/main/java/apijson/demo/DemoController.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
See the License for the specific language governing permissions and
1313
limitations under the License.*/
1414

15-
package apijson.boot.test;
15+
package apijson.demo;
1616

1717
import java.net.URLDecoder;
1818

@@ -30,6 +30,9 @@
3030
import apijson.orm.Parser;
3131

3232

33+
/**提供入口,转交给 APIJSON 的 Parser 来处理
34+
* @author Lemon
35+
*/
3336
@RestController
3437
@RequestMapping("")
3538
public class DemoController extends APIJSONController {
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 apijson.framework.APIJSONSQLConfig;
18+
19+
20+
/**SQL配置
21+
* TiDB 用法和 MySQL 一致
22+
* @author Lemon
23+
*/
24+
public class DemoSQLConfig extends APIJSONSQLConfig {
25+
26+
static {
27+
DEFAULT_DATABASE = DATABASE_MYSQL; // TODO 默认数据库类型,改成你自己的
28+
DEFAULT_SCHEMA = "sys"; // TODO 默认模式名,改成你自己的,默认情况是 MySQL: sys, PostgreSQL: public, SQL Server: dbo, Oracle:
29+
30+
// 表名和数据库不一致的,需要配置映射关系。只使用 APIJSONORM 时才需要;
31+
// 如果用了 apijson-framework 且调用了 APIJSONApplication.init
32+
// (间接调用 DemoVerifier.init 方法读取数据库 Access 表来替代手动输入配置),则不需要。
33+
// 但如果 Access 这张表的对外表名与数据库实际表名不一致,仍然需要这里注册。例如
34+
// TABLE_KEY_MAP.put(Access.class.getSimpleName(), "access");
35+
36+
//表名映射,隐藏真实表名,对安全要求很高的表可以这么做
37+
TABLE_KEY_MAP.put("User", "apijson_user");
38+
TABLE_KEY_MAP.put("Privacy", "apijson_privacy");
39+
}
40+
41+
@Override
42+
public String getDBVersion() {
43+
return "5.7.22"; // "8.0.11"; // TODO 改成你自己的 MySQL 或 PostgreSQL 数据库版本号 // MYSQL 8 和 7 使用的 JDBC 配置不一样
44+
}
45+
@Override
46+
public String getDBUri() {
47+
return "jdbc:mysql://localhost:3306"; // TODO 改成你自己的,TiDB 可以当成 MySQL 使用,默认端口为 4000
48+
}
49+
@Override
50+
public String getDBAccount() {
51+
return "root"; // TODO 改成你自己的
52+
}
53+
@Override
54+
public String getDBPassword() {
55+
return "apijson"; // TODO 改成你自己的,TiDB 可以当成 MySQL 使用, 默认密码为空字符串 ""
56+
}
57+
58+
}
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
# APIJSONFinal
12

2-
#### 运行
3+
APIJSON + JFinal 接近成品的 Demo
34

4-
右键 AppRunnableConfig > Run As > Java Application
5+
### 运行
6+
7+
右键 DemoAppConfig > Run As > Java Application
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

APIJSON-Java-Server/APIJSONFinal/pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@
2121
</dependency>
2222

2323
<!-- 可使用 libs 目录的 apijson-orm.jar 和 apijson-framework.jar 来替代,两种方式二选一 <<<<<<<<<< -->
24-
<dependency>
24+
<dependency>
2525
<groupId>com.github.Tencent</groupId>
2626
<artifactId>APIJSON</artifactId>
27-
<version>4.2.4</version>
27+
<version>4.2.5</version>
2828
</dependency>
2929
<dependency>
3030
<groupId>com.github.APIJSON</groupId>
3131
<artifactId>apijson-framework</artifactId>
32-
<version>4.4.0</version>
32+
<version>4.4.3</version>
3333
</dependency>
3434
<!-- 可使用 libs 目录的 apijson-orm.jar 和 apijson-framework.jar 来替代,两种方式二选一 >>>>>>>>>> -->
3535

@@ -148,7 +148,7 @@
148148
<transformers>
149149
<transformer
150150
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
151-
<mainClass>apijson.jfinal.AppRunnableConfig</mainClass>
151+
<mainClass>apijson.jfinal.DemoAppConfig</mainClass>
152152
</transformer>
153153

154154
<!-- 下面的配置支持排除指定文件打包到 jar 之中,可以用于排除需要修改的配置文件以便于在外部的 config 目录下的 同名配置文件生效,建议使用

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,13 @@ public DemoSQLConfig(RequestMethod method, String table) {
4141
DEFAULT_DATABASE = DATABASE_MYSQL; //TODO 默认数据库类型,改成你自己的
4242
DEFAULT_SCHEMA = "sys"; //TODO 默认模式名,改成你自己的,默认情况是 MySQL: sys, PostgreSQL: public, SQL Server: dbo, Oracle:
4343

44-
// 由 DemoVerifier.init 方法读取数据库 Access 表来替代手动输入配置
45-
// //表名映射,隐藏真实表名,对安全要求很高的表可以这么做
44+
//表名和数据库不一致的,需要配置映射关系。只使用 APIJSONORM 时才需要;
45+
//这个 Demo 用了 apijson-framework 且调用了 APIJSONApplication.init
46+
//(间接调用 DemoVerifier.init 方法读取数据库 Access 表来替代手动输入配置),所以不需要。
47+
//但如果 Access 这张表的对外表名与数据库实际表名不一致,仍然需要这里注册。例如
48+
// TABLE_KEY_MAP.put(Access.class.getSimpleName(), "access");
49+
50+
//表名映射,隐藏真实表名,对安全要求很高的表可以这么做
4651
// TABLE_KEY_MAP.put(User.class.getSimpleName(), "apijson_user");
4752
// TABLE_KEY_MAP.put(Privacy.class.getSimpleName(), "apijson_privacy");
4853

@@ -162,6 +167,12 @@ public String getDBPassword() {
162167
return null;
163168
}
164169

170+
//取消注释后,默认的 APIJSON 配置表会由业务表所在数据库模式 schema 改为自定义的
171+
// @Override
172+
// public String getConfigSchema() {
173+
// return "apijson";
174+
// }
175+
165176
//取消注释后,默认的数据库类型会由 MySQL 改为 PostgreSQL
166177
// @Override
167178
// public String getDatabase() {

APIJSON-Java-Server/APIJSONFinal/src/main/java/apijson/jfinal/AppRunnableConfig.java renamed to APIJSON-Java-Server/APIJSONFinal/src/main/java/apijson/jfinal/DemoAppConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
* 右键这个类 > Run As > Java Application
5454
* @author Lemon
5555
*/
56-
public class AppRunnableConfig extends JFinalConfig {
56+
public class DemoAppConfig extends JFinalConfig {
5757

5858
static {
5959
// APIJSON 配置 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
@@ -96,7 +96,7 @@ public SQLExecutor createSQLExecutor() {
9696

9797

9898
public static void main(String[] args) throws Exception {
99-
UndertowServer.start(AppRunnableConfig.class);
99+
UndertowServer.start(DemoAppConfig.class);
100100

101101
Log.DEBUG = true; // 上线生产环境前改为 false,可不输出 APIJSONORM 的日志 以及 SQLException 的原始(敏感)信息
102102
APIJSONApplication.init();

0 commit comments

Comments
 (0)