FIND_IN_SET 在mybatis的<foreach>中 使用

公司项目开发一个功能,制定标签,然后根据多标签查询;

最简单的还是标签做字典,这样,列表只要存一个  “,”    分割的字符串就行;

查询时候使用FIND_IN_SET   循环遍历出来就可以。

parameterType  是一个实体,
interfaceType 字段存的是   aa,bb,cc,dd,

foreach 要循环的是字符串,区别于循环list,所以要使用这个方法:(注意:sql语句 and中间没有  ,  所以要改一下 open="" close="" separator=" ")
where ………

<if test=" interfaceType != null and interfaceType != ''"> <foreach collection="interfaceType.split(',')" item="item" index="index" open="" close="" separator=" "> and FIND_IN_SET(#{item},m.interface_type) </foreach> </if>

 

posted @ 2022-07-12 20:48  百事没事  阅读(2021)  评论(0编辑  收藏  举报