Skip to content

Commit a78b709

Browse files
committed
简化字段插件 apijson-column 的示例代码
1 parent 0d68933 commit a78b709

File tree

4 files changed

+6
-48
lines changed

4 files changed

+6
-48
lines changed

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

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

1515
package apijson.boot;
1616

17+
import apijson.framework.APIJSONSQLConfig;
1718
import com.alibaba.fastjson.JSON;
1819
import com.alibaba.fastjson.JSONObject;
1920
import com.alibaba.fastjson.serializer.PropertyFilter;
@@ -92,6 +93,7 @@ public static void main(String[] args) throws Exception {
9293
// 上线生产环境前改为 false,可不输出 APIJSONORM 的日志 以及 SQLException 的原始(敏感)信息
9394
unitauto.Log.DEBUG = Log.DEBUG = true;
9495
APIJSONParser.IS_PRINT_BIG_LOG = true;
96+
// APIJSONSQLConfig.ENABLE_COLUMN_CONFIG = true; // apijson-framework 已集成字段插件 apijson-column,支持 !key 反选字段 和 字段名映射
9597
APIJSONApplication.init();
9698
APIJSONRouterApplication.init();
9799
System.out.println("\n\n<<<<<<<<< 本 Demo 在 resources/static 内置了 APIAuto,Chrome/Firefox 打开 http://localhost:8080 即可调试(端口号根据项目配置而定) ^_^ >>>>>>>>>\n");

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public String getRequestURL() {
129129
return httpServletRequest.getRequestURL().toString();
130130
}
131131

132-
/**增删改查统一的类 RESTful API 入口,牺牲一些路由解析性能来提升一点开发效率
132+
/**增删改查统一的类 RESTful API 入口,牺牲一点路由解析性能来提升一些开发效率
133133
* @param method
134134
* @param tag
135135
* @param params
@@ -145,7 +145,7 @@ public String router(@PathVariable String method, @PathVariable String tag, @Req
145145

146146
// 通用接口,非事务型操作 和 简单事务型操作 都可通过这些接口自动化实现 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
147147

148-
/**增删改查统一入口,这个一个方法可替代以下 7 个方法,牺牲一些路由解析性能来提升一点开发效率
148+
/**增删改查统一入口,这个一个方法可替代以下 7 个方法,牺牲一点路由解析性能来提升一些开发效率
149149
* @param method
150150
* @param request
151151
* @param session

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

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -109,33 +109,6 @@ public String getUserIdKey(String database, String schema, String datasource, St
109109
RAW_MAP.put("commentWhereItem1","(`Comment`.`userId` = 38710 AND `Comment`.`momentId` = 470)");
110110
RAW_MAP.put("to_days(now())-to_days(`date`)<=7", ""); // 给 @having 使用
111111
RAW_MAP.put("sexShowStr", "CASE sex WHEN 0 THEN '男' WHEN 1 THEN '女' ELSE '其它' END"); // 给 @having 使用
112-
113-
// 取消注释支持 !key 反选字段 和 字段名映射,需要先依赖插件 https://github.com/APIJSON/apijson-column
114-
115-
// 反选字段配置
116-
Map<String, List<String>> tableColumnMap = new HashMap<>();
117-
tableColumnMap.put("User", Arrays.asList(StringUtil.split("id,sex,name,tag,head,contactIdList,pictureList,date")));
118-
// 需要对应方法传参也是这样拼接才行,例如 ColumnUtil.compatInputColumn(column, getSQLDatabase() + "-" + getSQLSchema() + "-" + getTable(), getMethod());
119-
tableColumnMap.put("MYSQL-sys-Privacy", Arrays.asList(StringUtil.split("id,certified,phone,balance,_password,_payPassword")));
120-
ColumnUtil.VERSIONED_TABLE_COLUMN_MAP.put(null, tableColumnMap);
121-
122-
// 字段名映射配置 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
123-
Map<String, Map<String, String>> tableKeyColumnMap = new HashMap<>();
124-
125-
Map<String, String> userKeyColumnMap = new HashMap<>();
126-
userKeyColumnMap.put("gender", "sex");
127-
userKeyColumnMap.put("createTime", "date");
128-
tableKeyColumnMap.put("User", userKeyColumnMap);
129-
130-
Map<String, String> privacyKeyColumnMap = new HashMap<>();
131-
privacyKeyColumnMap.put("rest", "balance");
132-
// 需要对应方法传参也是这样拼接才行,例如 ColumnUtil.compatInputKey(super.getKey(key), getSQLDatabase() + "-" + getSQLSchema() + "-" + getTable(), getMethod());
133-
tableKeyColumnMap.put("MYSQL-sys-Privacy", privacyKeyColumnMap);
134-
135-
ColumnUtil.VERSIONED_KEY_COLUMN_MAP.put(null, tableKeyColumnMap);
136-
// 字段名映射配置 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
137-
138-
ColumnUtil.init();
139112
}
140113

141114

@@ -359,16 +332,6 @@ public void setSql(String sql) {
359332
// }
360333

361334

362-
// 取消注释支持 !key 反选字段 和 字段名映射,需要先依赖插件 https://github.com/APIJSON/apijson-column
363-
// @Override
364-
// public AbstractSQLConfig setColumn(List<String> column) {
365-
// return super.setColumn(ColumnUtil.compatInputColumn(column, getTable(), getMethod()));
366-
// }
367-
// @Override
368-
// public String getKey(String key) {
369-
// return super.getKey(ColumnUtil.compatInputKey(key, getTable(), getMethod()));
370-
// }
371-
372335
// 取消注释来兼容 Oracle DATETIME, TIMESTAMP 等日期时间类型的值来写库。5.0.0+ 重写以下方法,4.9.1 及以下改为重写 getValue(String)
373336
// @Override // 如果是查询,可以把 if 内 isQueryMethod 的判断去掉或者 boolean 值取反。
374337
// protected Object getValue(String key, String column, Object value) {
@@ -400,8 +363,8 @@ protected void onJoinNotRelation(String sql, String quote, Join j, String jt, Li
400363
// 开启 JOIN ON t1.c1 != t2.c2 等不等式关联 super.onJoinNotRelation(sql, quote, j, jt, onList, on);
401364
}
402365
@Override
403-
protected void onJoinComplextRelation(String sql, String quote, Join j, String jt, List<On> onList, On on) {
404-
// 开启 JOIN ON t1.c1 LIKE concat('%', t2.c2, '%') 等复杂关联 super.onJoinComplextRelation(sql, quote, j, jt, onList, on);
366+
protected void onJoinComplexRelation(String sql, String quote, Join join, String table, List<On> onList, On on) {
367+
// 开启 JOIN ON t1.c1 LIKE concat('%', t2.c2, '%') 等复杂关联 super.onJoinComplextRelation(sql, quote, join, table, onList, on);
405368
}
406369

407370

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -323,13 +323,6 @@ public JSONObject execute(@NotNull SQLConfig config, boolean unknownType) throws
323323
return super.execute(config, unknownType);
324324
}
325325

326-
// 取消注释支持 !key 反选字段 和 字段名映射,需要先依赖插件 https://github.com/APIJSON/apijson-column
327-
// @Override
328-
// protected String getKey(SQLConfig config, ResultSet rs, ResultSetMetaData rsmd, int tablePosition, JSONObject table,
329-
// int columnIndex, Map<String, JSONObject> childMap) throws Exception {
330-
// return ColumnUtil.compatOutputKey(super.getKey(config, rs, rsmd, tablePosition, table, columnIndex, childMap), config.getTable(), config.getMethod());
331-
// }
332-
333326
// 不需要隐藏字段这个功能时,取消注释来提升性能
334327
// @Override
335328
// protected boolean isHideColumn(SQLConfig config, ResultSet rs, ResultSetMetaData rsmd, int tablePosition,

0 commit comments

Comments
 (0)