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>
这帮我修好了!
关于java - MyBatis - 在嵌套的 foreach 循环中迭代列表,它是 HashMap 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32968851/