java - MyBatis - 在嵌套的 foreach 循环中迭代列表,它是 HashMap 的值

标签 java list foreach hashmap mybatis

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/

相关文章:

java - 可排序的类表 Java 类

java列表仅返回最后一个元素

forms - F# 将按钮列表添加到表单控件范围

javascript - 如何将 id 设置为 id h :commandLink from a c:forEach in order to be accesed by JS?

php - 如何检查变量是否为数组?...或类似数组的东西

java - 有没有一种优雅的方法可以对 Java 中的 for-each 循环的最后一个元素执行某些操作?

java - 如何配置GenericObjectPoolConfig?

java - 从括号部分拉出变量

java - 将下拉列表和文本框中的值传递给 JSP 中的 JavaScript

java - 什么类型返回get方法?