From 86b6dc1ef6dcad8b1fe7f8c128df1046e7b5e4e4 Mon Sep 17 00:00:00 2001 From: "youHong.ai" <774495953@qq.com> Date: Fri, 3 Mar 2023 17:40:03 +0800 Subject: [PATCH] for - map --- .../command/commandImpl/MyForCommand.java | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/test/java/youhong/ai/mymapper/command/commandImpl/MyForCommand.java b/src/test/java/youhong/ai/mymapper/command/commandImpl/MyForCommand.java index 0ebcfb1..2ed0fdc 100644 --- a/src/test/java/youhong/ai/mymapper/command/commandImpl/MyForCommand.java +++ b/src/test/java/youhong/ai/mymapper/command/commandImpl/MyForCommand.java @@ -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 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 entry : map.entrySet()) { + Map 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(); } }