mybatis动态sql对Map<String,List<String>>的遍历-原创

工作中需要查表,传来的参数是一个Map<String,List<String>>的参数,第一次对这样比较复杂的参数直接在mapping中进行条件遍历,查了一些帖子最终成功了,记录一下:

<if test="example.industryAndStyleList != null and example.industryAndStyleList.size() > 0">
AND(
<foreach collection="example.industryAndStyleList.entrySet()" separator=" OR " index="industry" item="styleLists" open="(" close=")">
b.label_industry LIKE CONCAT('%', #{industry}, '%')
<if test="styleLists != null and styleLists.size() > 0">
AND(
<foreach collection="styleLists" separator=" OR "
item="style" open="(" close=")">
b.recommend_tag LIKE CONCAT('%', #{style}, '%')
</foreach>
)
</if>
 </foreach>
 )
</if>

其中参数是来自后端传的一个集合example.industryAndStyleList,类型是Map<String,List<String>>,实际需求是查询多个行业(key,industry)下的多个风格(styleList List<String>),遍历需要两层foreach,第一层遍历key,要遍历的集合是example.industryAndStyleList.entrySet(),index对应key,别名为industry,item对应value,别名为styleList。第二层遍历value(List<String>),这一层foreach的集合名字就直接用第一层foreach的item的别名。第二层foreach遍历List,因此没有key就只有item=style。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值