如题,想要完成这样的Mybatis方法:
List<Bean> getList(@Param("totalMap") Map<String, Set<String>> totalMap);
完成类似:
where (clazz = '1' and date in ('1', '2', '3'))
or (clazz = '2' and date in ('2', '3', '4'))
or ...
这样的条件拼接。找了很多都没法用,AI给的答案也巨坑无比
正确写法(Mybatis3.3.2版本):
<select id="getList"
resultType="Bean">
SELECT
field1, field2
FROM
table
WHERE
<foreach item="item" index="key" collection="totalMap.entrySet()" separator="or">
(clazz = #{key} AND number IN
<foreach item="date" index="dateIndex" collection="item" open="(" separator="," close=")">
#{date}
</foreach>
)
</foreach>
GROUP BY group_id
</select>