How to Iterate through HashMap in MyBatis foreach?
this is an example in my project and it works fine
<select id="getObject" parameterType="Map" resultType="hashmap">
select * from TABL where
<foreach collection="dataMap" index="key" item="value" open="" separator=" and " close="">
#{key}=#{value}
</foreach>
</select>
This solution doesn't work since version 3.2 - see more in Issue #208 !
Finally I've the solution for HashMap
I Should use entrySet()
in order to make it iteratable
<select id="selectCOLC" parameterType="map" resultType="kpMap">
SELECT COL_C
FROM TBLE_1
WHERE (COL_A, COL_B) in
<foreach item="item" collection="entries.entrySet()" open="((" separator="),(" close="))">
#{item.key},#{item.value}
</foreach>
</select>
One more Isue I was facing parameter name was not getting injected, Hence added @Param
annotation
Hence mapper interface looks like below.
List<TblData> selectCOLC(@Param("entries")
HashMap<String, String> entries)