[英]mybatis: how to iterate a hashmap in a bean in mapper?
mapper interface:映射器接口:
List<Map<String, String>> selectXXXList(BeanA a);
BeanA:豆A:
private Map<String, String> map;
I need iterate this map in xxxMapper.xml.我需要在 xxxMapper.xml 中迭代这个地图。 I tried in this way, but it can not work.
我以这种方式尝试过,但无法正常工作。
<select id = "selectXXXList" resultType="hashMap">
SELECT * FROM tableA
WHERE
1=1
<foreach collection="a.map.keys" item="item" index="index" open="" seperator="" close="">
AND ${item} = #{a.map[${item}]}
</foreach>
<select>
It is able to iterator the key in this way.它能够以这种方式迭代密钥。 But the value of hashMap
#{a.map[${item}]}
does not work.但是 hashMap
#{a.map[${item}]}
不起作用。 Any idea?任何的想法? I can not change the interface BTW.
我不能改变界面 BTW。
Try this :尝试这个 :
<select id="selectXXXList" parameterType="beanA" resultType="hashmap">
select * from TABL where
<foreach collection="map" index="key" item="value" open="" separator=" and " close="">
${key}=#{value}
</foreach>
</select>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.