Java学习笔记

MyBatis的foreach语句详解

2016-07-22  本文已影响1135人  黄言黄语

经常在使用foreach是忘记其使用方式,做个笔记。

foreach元素属性

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

  1. item表示集合中每一个元素进行迭代时的别名
  2. index指 定一个名字,用于表示在迭代过程中,每次迭代到的位置
  3. open表示该语句以什么开始
  4. close表示以什么结束
  5. separator表示在每次进行迭代之间以什么符号作为分隔符
  6. collection传入的是参数

collection用法

<foreach item="item" index="index" collection="list" open="("     separator="," close=")">

     #{item}

</foreach>
<foreach item="item" index="index" collection="array" open="(" separator="," close=")">
    
    #{item}

</foreach>
<foreach item="item" index="index" collection= " xxx "  open="(" separator="," close=")">
    
    #{item}

</foreach>
上一篇 下一篇

猜你喜欢

热点阅读