MyBatis - 在嵌套的 foreach 循环中迭代列表,它是 HashMap 的值
MyBatis - Iterate over list which is value of HashMap in nested foreach loops
SELECT *
FROM mytable
<foreach item="item" index="index" collection="myhashmap.entrySet()" open=" WHERE (" separator=" OR ("> table.attribute= #{item.key}
<foreach item="item2" index="index" collection="#{item.value}" separator=" ," open=" AND table.attribute IN (" close="))">
#{item2.value}
</foreach>
</foreach>
hashmap 的迭代有效,但列表(在 item.value 中)无效。
Map<Integer, List<Integer>> myhashmap = new HashMap<Integer, List<Integer>>();
{item.value.iterator()} 也不行。
Exception:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.BuilderException: Error evaluating expression '#{item.value}'. Return value ({[5800]=null}) was not iterable.
其中 5800 是列表的整数值
感谢任何帮助!
<foreach item="element" index="index" collection="mySet.entrySet()" open=" WHERE ((" separator=" OR ("> table.attribute1= #{element.key}
<foreach item="item" index="index" collection="element.value" separator=" ," open=" AND table.attribute2 IN (" close="))">
#{item}
</foreach>
</foreach>
这帮我修好了!
SELECT *
FROM mytable
<foreach item="item" index="index" collection="myhashmap.entrySet()" open=" WHERE (" separator=" OR ("> table.attribute= #{item.key}
<foreach item="item2" index="index" collection="#{item.value}" separator=" ," open=" AND table.attribute IN (" close="))">
#{item2.value}
</foreach>
</foreach>
hashmap 的迭代有效,但列表(在 item.value 中)无效。
Map<Integer, List<Integer>> myhashmap = new HashMap<Integer, List<Integer>>();
{item.value.iterator()} 也不行。
Exception:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.BuilderException: Error evaluating expression '#{item.value}'. Return value ({[5800]=null}) was not iterable.
其中 5800 是列表的整数值
感谢任何帮助!
<foreach item="element" index="index" collection="mySet.entrySet()" open=" WHERE ((" separator=" OR ("> table.attribute1= #{element.key}
<foreach item="item" index="index" collection="element.value" separator=" ," open=" AND table.attribute2 IN (" close="))">
#{item}
</foreach>
</foreach>
这帮我修好了!