最近在编写程序的时候,遇到了需要传入map类型的查询条件,由于没有写过这样的代码,一时竟不知道该怎么写
询问了几位同事也没遇到过这样的写法,随对百度进行了数以百次的度,都没有查到想要的答案。搜的结果几乎都是map类型中value是object类型而非list类型。
随又经过几次尝试,竟试出来了,赶紧记录一下。
mybatis 接收Map类型,其中key为string,value为list方式的查询条件
dao层写入方法:
List<实体类> 方法名(@Param(value="content") Map<String, List<String>));
mapper层接收方法:
select
xxx
from xxx
where xxx
and
<foreach collection="content.keys" index="index" item="key" open="(" separator="or" close=")">
字段1=#{key}
and 字段2 in
<foreach collection="content[key]" index="index" item="value" open="(" separator="," close=")">
#{value]
</foreach>
</foreach>