Skip to content

Commit

Permalink
Java:APIJSONBoot 引入字段插件 apijson-column;升级 APIJSON, apijson-framework,…
Browse files Browse the repository at this point in the history
… 自身版本为 4.6.6
  • Loading branch information
TommyLemon committed Apr 5, 2021
1 parent 653bc18 commit bc50c04
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 20 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
21 changes: 14 additions & 7 deletions APIJSON-Java-Server/APIJSONBoot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>apijson.boot</groupId>
<artifactId>apijson-boot</artifactId>
<version>4.6.5</version>
<version>4.6.6</version>
<packaging>jar</packaging>

<name>APIJSONBoot</name>
Expand All @@ -32,7 +32,8 @@
<version>4.0.1</version>
</dependency>

<!-- 单元测试:可使用 libs 目录的 unitauto-java.jar 和 unitauto-jar.jar 来替代,两种方式二选一 <<<<<<<<< -->
<!-- 单元测试:可使用 libs 目录的 unitauto-java.jar 和 unitauto-jar.jar 来替代,两种方式二选一
<<<<<<<<< -->
<dependency>
<groupId>com.github.TommyLemon</groupId>
<artifactId>unitauto-java</artifactId>
Expand All @@ -48,21 +49,27 @@
<artifactId>classgraph</artifactId>
<version>4.8.87</version>
</dependency>
<!-- 单元测试:可使用 libs 目录的 unitauto-java.jar 和 unitauto-jar.jar 来替代,两种方式二选一 >>>>>>>>> -->
<!-- 单元测试:可使用 libs 目录的 unitauto-java.jar 和 unitauto-jar.jar 来替代,两种方式二选一
>>>>>>>>> -->


<!-- 可使用 libs 目录的 apijson-orm.jarapijson-framework.jar 来替代,两种方式二选一 <<<<<<<<<< -->
<!-- 可使用 libs 目录的 apijson-orm.jar, apijson-framework.jar, apijson-column.jar 来替代,两种方式二选一 <<<<<<<<<< -->
<dependency>
<groupId>com.github.Tencent</groupId>
<artifactId>APIJSON</artifactId>
<version>4.6.5</version>
<version>4.6.6</version>
</dependency>
<dependency>
<groupId>com.github.APIJSON</groupId>
<artifactId>apijson-framework</artifactId>
<version>4.6.5</version>
<version>4.6.6</version>
</dependency>
<!-- 可使用 libs 目录的 apijson-orm.jar 和 apijson-framework.jar 来替代,两种方式二选一 >>>>>>>>>> -->
<dependency>
<groupId>com.github.APIJSON</groupId>
<artifactId>apijson-column</artifactId>
<version>1.0.0</version>
</dependency>
<!-- 可使用 libs 目录的 apijson-orm.jar, apijson-framework.jar, apijson-column.jar 来替代,两种方式二选一 >>>>>>>>>> -->

<!-- 需要用的数据库 JDBC 驱动 -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,16 @@
import static apijson.framework.APIJSONConstant.USER_;
import static apijson.framework.APIJSONConstant.USER_ID;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.annotation.JSONField;

import apijson.RequestMethod;
import apijson.StringUtil;
import apijson.column.ColumnUtil;
import apijson.framework.APIJSONSQLConfig;
import apijson.orm.AbstractSQLConfig;

Expand Down Expand Up @@ -96,6 +103,34 @@ public String getUserIdKey(String database, String schema, String table) {
RAW_MAP.put("substring_index(substring_index(content,'.',1),'.',-1) AS subContent", ""); // APIAuto 不支持 ',可以用 Postman 测
RAW_MAP.put("commentWhereItem1","(`Comment`.`userId` = 38710 AND `Comment`.`momentId` = 470)");
RAW_MAP.put("to_days(now())-to_days(`date`)<=7",""); // 给 @having 使用


// 取消注释支持 !key 反选字段 和 字段名映射,需要先依赖插件 https://github.com/APIJSON/apijson-column

// 反选字段配置
Map<String, List<String>> tableColumnMap = new HashMap<>();
tableColumnMap.put("User", Arrays.asList(StringUtil.split("id,sex,name,tag,head,contactIdList,pictureList,date")));
// 需要对应方法传参也是这样拼接才行,例如 ColumnUtil.compatInputColumn(column, getSQLDatabase() + "-" + getSQLSchema() + "-" + getTable(), getMethod());
tableColumnMap.put("MYSQL-sys-Privacy", Arrays.asList(StringUtil.split("id,certified,phone,balance,_password,_payPassword")));
ColumnUtil.VERSIONED_TABLE_COLUMN_MAP.put(null, tableColumnMap);

// 字段名映射配置 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Map<String, Map<String, String>> tableKeyColumnMap = new HashMap<>();

Map<String, String> userKeyColumnMap = new HashMap<>();
userKeyColumnMap.put("gender", "sex");
userKeyColumnMap.put("createTime", "date");
tableKeyColumnMap.put("User", userKeyColumnMap);

Map<String, String> privacyKeyColumnMap = new HashMap<>();
privacyKeyColumnMap.put("rest", "balance");
// 需要对应方法传参也是这样拼接才行,例如 ColumnUtil.compatInputKey(super.getKey(key), getSQLDatabase() + "-" + getSQLSchema() + "-" + getTable(), getMethod());
tableKeyColumnMap.put("MYSQL-sys-Privacy", privacyKeyColumnMap);

ColumnUtil.VERSIONED_KEY_COLUMN_MAP.put(null, tableKeyColumnMap);
// 字段名映射配置 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

ColumnUtil.init();
}


Expand All @@ -120,7 +155,7 @@ public String getDBVersion() {
}
return null;
}

@JSONField(serialize = false) // 不在日志打印 账号/密码 等敏感信息,用了 UnitAuto 则一定要加
@Override
public String getDBUri() {
Expand All @@ -143,7 +178,7 @@ public String getDBUri() {
}
return null;
}

@JSONField(serialize = false) // 不在日志打印 账号/密码 等敏感信息,用了 UnitAuto 则一定要加
@Override
public String getDBAccount() {
Expand All @@ -164,7 +199,7 @@ public String getDBAccount() {
}
return null;
}

@JSONField(serialize = false) // 不在日志打印 账号/密码 等敏感信息,用了 UnitAuto 则一定要加
@Override
public String getDBPassword() {
Expand Down Expand Up @@ -225,4 +260,14 @@ public String getDBPassword() {
// return false;
// }


// 取消注释支持 !key 反选字段 和 字段名映射,需要先依赖插件 https://github.com/APIJSON/apijson-column
@Override
public AbstractSQLConfig setColumn(List<String> column) {
return super.setColumn(ColumnUtil.compatInputColumn(column, getTable(), getMethod()));
}
@Override
public String getKey(String key) {
return ColumnUtil.compatInputKey(super.getKey(key), getTable(), getMethod());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,18 @@

package apijson.demo;

import java.sql.Connection;

import javax.sql.DataSource;

import apijson.Log;
import apijson.boot.DemoApplication;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.util.Map;

import javax.sql.DataSource;

import com.alibaba.fastjson.JSONObject;

import apijson.Log;
import apijson.boot.DemoApplication;
import apijson.column.ColumnUtil;
import apijson.framework.APIJSONSQLExecutor;
import apijson.orm.SQLConfig;

Expand Down Expand Up @@ -63,6 +69,14 @@ public Connection getConnection(SQLConfig config) throws Exception {
// 必须最后执行 super 方法,因为里面还有事务相关处理。
// 如果这里是 return c,则会导致 增删改 多个对象时只有第一个会 commit,即只有第一个对象成功插入数据库表
return super.getConnection(config);
}


// 取消注释支持 !key 反选字段 和 字段名映射,需要先依赖插件 https://github.com/APIJSON/apijson-column
@Override
protected String getKey(SQLConfig config, ResultSet rs, ResultSetMetaData rsmd, int tablePosition, JSONObject table,
int columnIndex, Map<String, JSONObject> childMap) throws Exception {
return ColumnUtil.compatOutputKey(super.getKey(config, rs, rsmd, tablePosition, table, columnIndex, childMap), config.getTable(), config.getMethod());
}

}
2 changes: 1 addition & 1 deletion APIJSON-Java-Server/APIJSONDemo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>apijson.demo</groupId>
<artifactId>apijson-demo</artifactId>
<version>4.6.5</version>
<version>4.6.6</version>
<packaging>jar</packaging>

<name>APIJSONDemo</name>
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
6 changes: 3 additions & 3 deletions APIJSON-Java-Server/APIJSONFinal/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>apijson.jfinal</groupId>
<artifactId>apijson-final</artifactId>
<packaging>jar</packaging>
<version>4.6.5</version>
<version>4.6.6</version>
<name>Demo project for APIJSON Server based on JFinal</name>
<url>http://maven.apache.org</url>
<dependencies>
Expand All @@ -26,12 +26,12 @@
<dependency>
<groupId>com.github.Tencent</groupId>
<artifactId>APIJSON</artifactId>
<version>4.6.5</version>
<version>4.6.6</version>
</dependency>
<dependency>
<groupId>com.github.APIJSON</groupId>
<artifactId>apijson-framework</artifactId>
<version>4.6.5</version>
<version>4.6.6</version>
</dependency>
<!-- 可使用 libs 目录的 apijson-orm.jar 和 apijson-framework.jar 来替代,两种方式二选一 >>>>>>>>>> -->

Expand Down

0 comments on commit bc50c04

Please sign in to comment.