需求:根据id模糊匹配相应的数据,因为每条数据中有好多id,所以要模糊匹配。
参数为id的list集合 返回map
<select id="aa" resultType="java.util.Map" parameterType="java.util.List">
select * from scf_core_enterprise_user where 1 = 1 AND
<if test="list != null and list.size() > 0">
and account_status in
<foreach item="status" index="index" collection="list" open="(" separator="," close=")">
#{status}
</foreach>
</if>
</select>
查询效果图如下:
顺便分享一个mybatis遍历循环in的方法
1、外边传入的是list
<select id="bb" resultType="java.util.Map" parameterType="java.util.List">
<if test="accountStatusList != null and accountStatusList.size() > 0">
and account_status in
<foreach item="accountStatus" index="index" collection="accountStatusList" open="(" separator="," close=")">
#{accountStatus}
</foreach>
</if>
</select>
2、外边传入的是逗号分割的字符串
<foreach item="item" index="index" collection="id.split(',')" open="(" separator="," close=")">
(#{item})
</foreach>