for - map

main
youHong.ai 2023-03-03 17:40:03 +08:00
parent 08a396fe40
commit 86b6dc1ef6
1 changed files with 33 additions and 2 deletions

View File

@ -143,7 +143,7 @@ public class MyForCommand implements ISqlCommand {
ParseSqlUtil.PARSE_TEMP_PARAM_LOCALE.set(tempParam);
String parse = parseSqlUtil.parse(properties.getCommandContent());
sqlBuilder.append(" ").append(parse);
if (i <= list.size()) {
if (i < list.size() - 1) {
sqlBuilder.append(separator);
}
ParseSqlUtil.PARSE_TEMP_PARAM_LOCALE.remove();
@ -153,6 +153,37 @@ public class MyForCommand implements ISqlCommand {
}
private String mapCommand(Object value, MyForProperties properties) {
return null;
Map<Object, Object> map = (Map) value;
String itemName = properties.getItem();
if (StringUtil.isNullOrEmpty(itemName)) {
itemName = "item";
}
String indexName = properties.getIndex();
if (StringUtil.isNullOrEmpty(indexName)) {
indexName = "index";
}
if (map.isEmpty()) {
return null;
}
StringBuilder sqlBuilder = new StringBuilder();
String open = properties.getOpen();
String close = properties.getClose();
String separator = properties.getSeparator();
sqlBuilder.append(open);
int i = 0;
for (Map.Entry<Object, Object> entry : map.entrySet()) {
Map<String, Object> tempParam = new HashMap<>();
tempParam.put(itemName, entry.getValue());
tempParam.put(indexName, entry.getKey());
ParseSqlUtil.PARSE_TEMP_PARAM_LOCALE.set(tempParam);
String parse = parseSqlUtil.parse(properties.getCommandContent());
sqlBuilder.append(" ").append(parse);
if (i < map.size() - 1) {
sqlBuilder.append(separator);
}
ParseSqlUtil.PARSE_TEMP_PARAM_LOCALE.remove();
}
sqlBuilder.append(close);
return sqlBuilder.toString();
}
}