簡體   English   中英

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>  

這為我修好了!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM