Struts2 OGNL集合的遍历

 <li>遍历集合:<br/>

  <s:iteratorvalue="{1,2,3,4,5}">

     <s:property/>||

  </s:iterator>   

  <li>自定义变量:<br/>

  <s:iteratorvalue="{'aaa','bbb','ccc','ddd','eee'}" var="x">

     <s:propertyvalue="#x.toUpperCase()"/>

  </s:iterator>

  <li>使用status属性:<br/>

  <s:iteratorvalue="{'aaa','bbb','ccc','ddd','eee'}" status="st">

     <s:property />|

     遍历过的元素总数:<s:propertyvalue="#st.count"/>|

      遍历过的元素索引:<s:propertyvalue="#st.index"/>|

       当前是偶数?:<s:propertyvalue="#st.even"/>|

       当前是奇数?:<s:property value="#st.odd"/>|

        是第一个元素吗?:<s:propertyvalue="#st.first"/>|

        是最后一个元素吗?:<s:propertyvalue="#st.last"/>|

   <br/>

  </s:iterator>

  <li>遍历Map集合:<br/>

  <s:iterator value="#{1:'a',2:'b',3:'c',4:'d'}">

     <s:propertyvalue="key"/>|<s:propertyvalue="value"/><br/>

  </s:iterator>

  <hr/>

  <s:iteratorvalue="#{1:'a',2:'b',3:'c',4:'d'}" var="x">

     <s:propertyvalue="#x.key"/>|<s:propertyvalue="#x.value"/><br/>

</s:iterator>

猜你喜欢

转载自blog.csdn.net/qq_37668945/article/details/80952416