I'm trying to produce a sql which is as below in mybatis.
SELECT COL_C
FROM TBLE_1
WHERE (COL_A, COL_B) in ( ('kp','kar'),('srt','sach'));
And my input parameter type is HashMap. Now How do I generate SQL from mapper xml file. The below code throws exception saying map evaluated to null.
SELECT COL_C
FROM TBLE_1
WHERE (COL_A, COL_B) in
#{item},#{item.get(item)}
One of the other approach is to create a class with key value fields, create a list of object and then pass the parameterType as list which would look like following.
SELECT COL_C
FROM TBLE_1
WHERE (COL_A, COL_B) in
#{item.getKey()},#{item.getVal()}
But is there any way to my mapper work for the first approach? other than changing the query to union
解决方案
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 COL_C
FROM TBLE_1
WHERE (COL_A, COL_B) in
#{item.key},#{item.value}
One more Isue I was facing parameter name was not getting injected, Hence added @Param annotation
Hence mapper interface looks like below.
List selectCOLC(@Param("entries")
HashMap entries)