Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bc50c04

Browse files
Java:APIJSONBoot 引入字段插件 apijson-column;升级 APIJSON, apijson-framework, 自身版本为 4.6.6
1 parent 653bc18 commit bc50c04

File tree

14 files changed

+86
-20
lines changed

14 files changed

+86
-20
lines changed
14.6 KB
Binary file not shown.
-38.8 KB
Binary file not shown.
65.2 KB
Binary file not shown.
-162 KB
Binary file not shown.
287 KB
Binary file not shown.

‎APIJSON-Java-Server/APIJSONBoot/pom.xml

Lines changed: 14 additions & 7 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.6.5</version>
8+
<version>4.6.6</version>
99
<packaging>jar</packaging>
1010

1111
<name>APIJSONBoot</name>
@@ -32,7 +32,8 @@
3232
<version>4.0.1</version>
3333
</dependency>
3434

35-
<!-- 单元测试:可使用 libs 目录的 unitauto-java.jar 和 unitauto-jar.jar 来替代,两种方式二选一 <<<<<<<<< -->
35+
<!-- 单元测试:可使用 libs 目录的 unitauto-java.jar 和 unitauto-jar.jar 来替代,两种方式二选一
36+
<<<<<<<<< -->
3637
<dependency>
3738
<groupId>com.github.TommyLemon</groupId>
3839
<artifactId>unitauto-java</artifactId>
@@ -48,21 +49,27 @@
4849
<artifactId>classgraph</artifactId>
4950
<version>4.8.87</version>
5051
</dependency>
51-
<!-- 单元测试:可使用 libs 目录的 unitauto-java.jar 和 unitauto-jar.jar 来替代,两种方式二选一 >>>>>>>>> -->
52+
<!-- 单元测试:可使用 libs 目录的 unitauto-java.jar 和 unitauto-jar.jar 来替代,两种方式二选一
53+
>>>>>>>>> -->
5254

5355

54-
<!-- 可使用 libs 目录的 apijson-orm.jarapijson-framework.jar 来替代,两种方式二选一 <<<<<<<<<< -->
56+
<!-- 可使用 libs 目录的 apijson-orm.jar, apijson-framework.jar, apijson-column.jar 来替代,两种方式二选一 <<<<<<<<<< -->
5557
<dependency>
5658
<groupId>com.github.Tencent</groupId>
5759
<artifactId>APIJSON</artifactId>
58-
<version>4.6.5</version>
60+
<version>4.6.6</version>
5961
</dependency>
6062
<dependency>
6163
<groupId>com.github.APIJSON</groupId>
6264
<artifactId>apijson-framework</artifactId>
63-
<version>4.6.5</version>
65+
<version>4.6.6</version>
6466
</dependency>
65-
<!-- 可使用 libs 目录的 apijson-orm.jar 和 apijson-framework.jar 来替代,两种方式二选一 >>>>>>>>>> -->
67+
<dependency>
68+
<groupId>com.github.APIJSON</groupId>
69+
<artifactId>apijson-column</artifactId>
70+
<version>1.0.0</version>
71+
</dependency>
72+
<!-- 可使用 libs 目录的 apijson-orm.jar, apijson-framework.jar, apijson-column.jar 来替代,两种方式二选一 >>>>>>>>>> -->
6673

6774
<!-- 需要用的数据库 JDBC 驱动 -->
6875
<dependency>

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

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,16 @@
1919
import static apijson.framework.APIJSONConstant.USER_;
2020
import static apijson.framework.APIJSONConstant.USER_ID;
2121

22+
import java.util.Arrays;
23+
import java.util.HashMap;
24+
import java.util.List;
25+
import java.util.Map;
26+
2227
import com.alibaba.fastjson.annotation.JSONField;
2328

2429
import apijson.RequestMethod;
30+
import apijson.StringUtil;
31+
import apijson.column.ColumnUtil;
2532
import apijson.framework.APIJSONSQLConfig;
2633
import apijson.orm.AbstractSQLConfig;
2734

@@ -96,6 +103,34 @@ public String getUserIdKey(String database, String schema, String table) {
96103
RAW_MAP.put("substring_index(substring_index(content,'.',1),'.',-1) AS subContent", ""); // APIAuto 不支持 ',可以用 Postman 测
97104
RAW_MAP.put("commentWhereItem1","(`Comment`.`userId` = 38710 AND `Comment`.`momentId` = 470)");
98105
RAW_MAP.put("to_days(now())-to_days(`date`)<=7",""); // 给 @having 使用
106+
107+
108+
// 取消注释支持 !key 反选字段 和 字段名映射,需要先依赖插件 https://github.com/APIJSON/apijson-column
109+
110+
// 反选字段配置
111+
Map<String, List<String>> tableColumnMap = new HashMap<>();
112+
tableColumnMap.put("User", Arrays.asList(StringUtil.split("id,sex,name,tag,head,contactIdList,pictureList,date")));
113+
// 需要对应方法传参也是这样拼接才行,例如 ColumnUtil.compatInputColumn(column, getSQLDatabase() + "-" + getSQLSchema() + "-" + getTable(), getMethod());
114+
tableColumnMap.put("MYSQL-sys-Privacy", Arrays.asList(StringUtil.split("id,certified,phone,balance,_password,_payPassword")));
115+
ColumnUtil.VERSIONED_TABLE_COLUMN_MAP.put(null, tableColumnMap);
116+
117+
// 字段名映射配置 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
118+
Map<String, Map<String, String>> tableKeyColumnMap = new HashMap<>();
119+
120+
Map<String, String> userKeyColumnMap = new HashMap<>();
121+
userKeyColumnMap.put("gender", "sex");
122+
userKeyColumnMap.put("createTime", "date");
123+
tableKeyColumnMap.put("User", userKeyColumnMap);
124+
125+
Map<String, String> privacyKeyColumnMap = new HashMap<>();
126+
privacyKeyColumnMap.put("rest", "balance");
127+
// 需要对应方法传参也是这样拼接才行,例如 ColumnUtil.compatInputKey(super.getKey(key), getSQLDatabase() + "-" + getSQLSchema() + "-" + getTable(), getMethod());
128+
tableKeyColumnMap.put("MYSQL-sys-Privacy", privacyKeyColumnMap);
129+
130+
ColumnUtil.VERSIONED_KEY_COLUMN_MAP.put(null, tableKeyColumnMap);
131+
// 字段名映射配置 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
132+
133+
ColumnUtil.init();
99134
}
100135

101136

@@ -120,7 +155,7 @@ public String getDBVersion() {
120155
}
121156
return null;
122157
}
123-
158+
124159
@JSONField(serialize = false) // 不在日志打印 账号/密码 等敏感信息,用了 UnitAuto 则一定要加
125160
@Override
126161
public String getDBUri() {
@@ -143,7 +178,7 @@ public String getDBUri() {
143178
}
144179
return null;
145180
}
146-
181+
147182
@JSONField(serialize = false) // 不在日志打印 账号/密码 等敏感信息,用了 UnitAuto 则一定要加
148183
@Override
149184
public String getDBAccount() {
@@ -164,7 +199,7 @@ public String getDBAccount() {
164199
}
165200
return null;
166201
}
167-
202+
168203
@JSONField(serialize = false) // 不在日志打印 账号/密码 等敏感信息,用了 UnitAuto 则一定要加
169204
@Override
170205
public String getDBPassword() {
@@ -225,4 +260,14 @@ public String getDBPassword() {
225260
// return false;
226261
// }
227262

263+
264+
// 取消注释支持 !key 反选字段 和 字段名映射,需要先依赖插件 https://github.com/APIJSON/apijson-column
265+
@Override
266+
public AbstractSQLConfig setColumn(List<String> column) {
267+
return super.setColumn(ColumnUtil.compatInputColumn(column, getTable(), getMethod()));
268+
}
269+
@Override
270+
public String getKey(String key) {
271+
return ColumnUtil.compatInputKey(super.getKey(key), getTable(), getMethod());
272+
}
228273
}

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

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,18 @@
1414

1515
package apijson.demo;
1616

17-
import java.sql.Connection;
18-
19-
import javax.sql.DataSource;
20-
21-
import apijson.Log;
22-
import apijson.boot.DemoApplication;
17+
import java.sql.Connection;
18+
import java.sql.ResultSet;
19+
import java.sql.ResultSetMetaData;
20+
import java.util.Map;
21+
22+
import javax.sql.DataSource;
23+
24+
import com.alibaba.fastjson.JSONObject;
25+
26+
import apijson.Log;
27+
import apijson.boot.DemoApplication;
28+
import apijson.column.ColumnUtil;
2329
import apijson.framework.APIJSONSQLExecutor;
2430
import apijson.orm.SQLConfig;
2531

@@ -63,6 +69,14 @@ public Connection getConnection(SQLConfig config) throws Exception {
6369
// 必须最后执行 super 方法,因为里面还有事务相关处理。
6470
// 如果这里是 return c,则会导致 增删改 多个对象时只有第一个会 commit,即只有第一个对象成功插入数据库表
6571
return super.getConnection(config);
72+
}
73+
74+
75+
// 取消注释支持 !key 反选字段 和 字段名映射,需要先依赖插件 https://github.com/APIJSON/apijson-column
76+
@Override
77+
protected String getKey(SQLConfig config, ResultSet rs, ResultSetMetaData rsmd, int tablePosition, JSONObject table,
78+
int columnIndex, Map<String, JSONObject> childMap) throws Exception {
79+
return ColumnUtil.compatOutputKey(super.getKey(config, rs, rsmd, tablePosition, table, columnIndex, childMap), config.getTable(), config.getMethod());
6680
}
6781

6882
}

‎APIJSON-Java-Server/APIJSONDemo/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>apijson.demo</groupId>
77
<artifactId>apijson-demo</artifactId>
8-
<version>4.6.5</version>
8+
<version>4.6.6</version>
99
<packaging>jar</packaging>
1010

1111
<name>APIJSONDemo</name>
-38.8 KB
Binary file not shown.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /