有种需求:根据输入的内容的个数设置不同个数的查询条件(在一个列上设置不定个数的查询条件),这时就需要根据foreach循环在一个列上拼接查询条件了。

1、parameterType为List

<select id="tenantSelect" parameterType="java.util.List" resultMap="tenantRegxStatus">
    select tenant_id,
    abnormal_id,
    create_time,
    valid
    from tb_tenant_regx_status
    <if test="list!=null and list.size()>0">
        where tenant_id in
        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
    </if>
</select>

2、parameterType为Map

Mybatis使用心得

 

相关文章: