XML中的foreach

foreach元素的属性主要有 collection,item,index,separator,open,close。

collection:表示集合,数据源

item :表示集合中的每一个元素

index :用于表示在迭代过程中,每次迭代到的位置

separator :表示在迭代时数据以什么符号作为分隔符

open :表示该语句以什么开始

close :表示以什么结束

代码示例:

data数据类型为List<Map<String,object>>

update order_info o set o.state=#{state}
<where>
<if test="data!=null">
<foreach collection="data" item="map" index="index" separator=",">
or o.id=#{map.orderId}
</foreach>
</if>
</where>

猜你喜欢

转载自www.cnblogs.com/aaron95/p/11387521.html