Skip to content

Commit f2d4fc2

Browse files
committed
Server:连续范围 key%:[] 由 [1,2] 改为 ['1,2', '3,4'...];StringUtil.split 默认严格匹配分隔符
1 parent 70b2283 commit f2d4fc2

File tree

2 files changed

+68
-36
lines changed

2 files changed

+68
-36
lines changed

APIJSON-Java-Server/APIJSONLibrary/src/main/java/zuo/biao/apijson/StringUtil.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,16 @@ public static String[] split(String s) {
743743
* @return
744744
*/
745745
public static String[] split(String s, String split) {
746-
return split(s, split, true);
746+
return split(s, split, false);
747+
}
748+
/**将s用split分割成String[]
749+
* split = null
750+
* @param s
751+
* @param trim 去掉前后两端的split
752+
* @return
753+
*/
754+
public static String[] split(String s, boolean trim) {
755+
return split(s, null, trim);
747756
}
748757
/**将s用split分割成String[]
749758
* @param s

APIJSON-Java-Server/APIJSONLibrary/src/main/java/zuo/biao/apijson/server/AbstractSQLConfig.java

Lines changed: 58 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ public String getColumnString() throws Exception {
501501
if (j.isAppJoin()) {
502502
continue;
503503
}
504-
504+
505505
c = j.getJoinConfig();
506506
c.setAlias(c.getTable());
507507
joinColumn += (first ? "" : ", ") + ((AbstractSQLConfig) c).getColumnString();
@@ -641,7 +641,7 @@ public String getColumnString() throws Exception {
641641
}
642642
}
643643

644-
644+
645645
@Override
646646
public List<List<Object>> getValues() {
647647
return values;
@@ -1214,7 +1214,7 @@ public String getSearchString(String key, Object[] values, int type) throws Ille
12141214
}
12151215

12161216
/**WHERE key LIKE 'value'
1217-
* @param key endsWith("!") ? key = key.substring(0, key.length() - 1) + NOT;
1217+
* @param key
12181218
* @param value
12191219
* @return key LIKE 'value'
12201220
*/
@@ -1292,51 +1292,74 @@ public String getRegExpString(String key, String value, boolean ignoreCase) {
12921292

12931293
//% between <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
12941294

1295-
/**WHERE key BETWEEN 'value0' AND 'value1'
1295+
/**WHERE key BETWEEN 'start' AND 'end'
12961296
* @param key
1297-
* @param value
1298-
* @return key BETWEEN 'value0' AND 'value1'
1297+
* @param value 'start,end'
1298+
* @return LOGIC [ key BETWEEN 'start' AND 'end' ]
1299+
* @throws IllegalArgumentException
12991300
*/
13001301
@JSONField(serialize = false)
1301-
public String getBetweenString(String key, Object value) {
1302-
boolean not = key.endsWith("!"); //不能用 new Logic(key) 因为默认是 | ,而 BETWEEN 只能接 AND
1303-
if (not) {
1304-
key = key.substring(0, key.length() - 1);
1305-
}
1306-
if (StringUtil.isName(key) == false) {
1307-
throw new IllegalArgumentException(key + "%:value 中key不合法!不支持 ! 以外的逻辑符 !");
1302+
public String getBetweenString(String key, Object value) throws IllegalArgumentException {
1303+
if (value == null) {
1304+
return "";
13081305
}
13091306

1310-
Object[] vs;
1311-
if (value instanceof String) {
1312-
vs = StringUtil.split((String) value);
1313-
// int index = ((String) value).indexOf(",");
1314-
// if (index < 0) {
1315-
// throw new IllegalArgumentException(key + "%:value 中value的类型为 String 时必须包括逗号 , !前面缺省为 min(key) ,后面缺省为 max(key)");
1316-
// }
1317-
// if (index == 0) {
1318-
// start = "(SELECT min(key) FROM getSQLTable())"
1319-
// }
1320-
}
1321-
else if (value instanceof Collection<?>) {
1322-
vs = ((Collection<?>) value).toArray();
1307+
Logic logic = new Logic(key);
1308+
key = logic.getKey();
1309+
Log.i(TAG, "getBetweenString key = " + key);
1310+
1311+
JSONArray arr = newJSONArray(value);
1312+
if (arr.isEmpty()) {
1313+
return "";
13231314
}
1324-
else {
1325-
throw new IllegalArgumentException(key + "%:value 中value不合法!类型只能为 1个逗号分隔的String 或者 只有Boolean[2]或Number[2]或String[2] !");
1315+
return getBetweenString(key, arr.toArray(), logic.getType());
1316+
}
1317+
1318+
/**WHERE key BETWEEN 'start' AND 'end'
1319+
* @param key
1320+
* @param value 'start,end' TODO 在 '1,2' 和 ['1,2', '3,4'] 基础上新增支持 [1, 2] 和 [[1,2], [3,4]] ?
1321+
* @return LOGIC [ key BETWEEN 'start' AND 'end' ]
1322+
* @throws IllegalArgumentException
1323+
*/
1324+
@JSONField(serialize = false)
1325+
public String getBetweenString(String key, Object[] values, int type) throws IllegalArgumentException {
1326+
if (values == null || values.length <= 0) {
1327+
return "";
13261328
}
13271329

1328-
if (vs == null || vs.length != 2) {
1329-
throw new IllegalArgumentException(key + "%:value 中value不合法!类型为 String 时必须包括1个逗号 , 且左右两侧都有值!类型为 JSONArray 时只能是 Boolean[2]或Number[2]或String[2] !");
1330+
String condition = "";
1331+
String[] vs;
1332+
for (int i = 0; i < values.length; i++) {
1333+
if (values[i] instanceof String == false) {
1334+
throw new IllegalArgumentException(key + "%:value 中 value 的类型只能为 String 或 String[] !");
1335+
}
1336+
1337+
vs = StringUtil.split((String) values[i]);
1338+
if (vs == null || vs.length != 2) {
1339+
throw new IllegalArgumentException(key + "%:value 中 value 不合法!类型为 String 时必须包括1个逗号 , 且左右两侧都有值!类型为 String[] 里面每个元素要符合前面类型为 String 的规则 !");
1340+
}
1341+
1342+
condition += (i <= 0 ? "" : (Logic.isAnd(type) ? AND : OR)) + "(" + getBetweenString(key, vs[0], vs[1]) + ")";
13301343
}
13311344

1332-
Object start = vs[0];
1333-
Object end = vs[1];
1345+
return getCondition(Logic.isNot(type), condition);
1346+
}
1347+
1348+
/**WHERE key BETWEEN 'start' AND 'end'
1349+
* @param key
1350+
* @param value 'start,end' TODO 在 '1,2' 和 ['1,2', '3,4'] 基础上新增支持 [1, 2] 和 [[1,2], [3,4]] ?
1351+
* @return key BETWEEN 'start' AND 'end'
1352+
* @throws IllegalArgumentException
1353+
*/
1354+
@JSONField(serialize = false)
1355+
public String getBetweenString(String key, Object start, Object end) throws IllegalArgumentException {
13341356
if (JSON.isBooleanOrNumberOrString(start) == false || JSON.isBooleanOrNumberOrString(end) == false) {
1335-
throw new IllegalArgumentException(key + "%:value 中value不合法!类型为 String 时必须包括1个逗号 , 且左右两侧都有值!类型为 JSONArray 时只能是 Boolean[2]或Number[2]或String[2] !");
1357+
throw new IllegalArgumentException(key + "%:value 中 value 不合法!类型为 String 时必须包括1个逗号 , 且左右两侧都有值!类型为 String[] 里面每个元素要符合前面类型为 String 的规则 !");
13361358
}
1337-
1338-
return getKey(key) + (not ? NOT : "") + " BETWEEN " + getValue(start) + AND + getValue(end);
1359+
return getKey(key) + " BETWEEN " + getValue(start) + AND + getValue(end);
13391360
}
1361+
1362+
13401363
//% between >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
13411364

13421365

0 commit comments

Comments
 (0)