Skip to content

Commit 96ee66a

Browse files
committed
Java:APIJSONBoot 新增更多 原始 SQL 片段 @raw:"key" 的配置示例
1 parent bfe94c9 commit 96ee66a

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,15 @@ public String getUserIdKey(String database, String schema, String table) {
8484
// }
8585
};
8686

87-
// 自定义where条件拼接
88-
//RAW_MAP.put("commentWhereItem1","`Comment`.`userId` = 38710 and `Comment`.`momentId` = 470");
89-
//RAW_MAP.put("commentWhereItem2","`Comment`.`toId` = 0");
87+
// 自定义原始 SQL 片段,其它功能满足不了时才用它,只有 RAW_MAP 配置了的 key 才允许前端传
88+
RAW_MAP.put("`to`.`id`", ""); // 空字符串 "" 表示用 key 的值 `to`.`id`
89+
RAW_MAP.put("to.momentId", "`to`.`momentId`"); // 最终以 `to`.`userId` 拼接 SQL,相比以上写法可以让前端写起来更简单
90+
RAW_MAP.put("(`Comment`.`userId`=`to`.`userId`)", ""); // 已经是一个条件表达式了,用 () 包裹是为了避免 JSON 中的 key 拼接在前面导致 SQL 出错
91+
RAW_MAP.put("sum(if(userId%2=0,1,0))", ""); // 超过单个函数的 SQL 表达式
92+
RAW_MAP.put("sumUserIdIsEven", "sum(if(`userId`%2=0,1,0)) AS sumUserIdIsEven"); // 简化前端传参
93+
RAW_MAP.put("SUBSTRING_INDEX(SUBSTRING_INDEX(content,',',1),',',-1)", ""); // APIAuto 不支持 ',可以用 Postman 测
94+
RAW_MAP.put("SUBSTRING_INDEX(SUBSTRING_INDEX(content,'.',1),'.',-1) AS subContent", ""); // APIAuto 不支持 ',可以用 Postman 测
95+
RAW_MAP.put("commentWhereItem1","(`Comment`.`userId` = 38710 AND `Comment`.`momentId` = 470)");
9096
}
9197

9298

0 commit comments

Comments
 (0)