mybatis where 条件为list集合处理

来源:互联网 发布:asp通用查询系统源码 编辑:程序博客网 时间:2024/06/05 17:24

在mybatis 编写sql时,常常会遇到条件为list的一个集合,我们在xml里如何进行遍历呢?

代码如下:

 <if test="ids!=null and ids!='' and ids.size()>0">
            id in
            <foreach collection="ids"item="item" index="index"
                     open="(" separator="," close=")">#{item}
            </foreach>
 </if>

collection: 传递过来的name 参数集合

item:遍历的每一个子项。

open:动态拼接子项的前缀。

separator:分割字符

close:结尾拼接。


阅读全文
0 0