1. 程式人生 > >s:iterator標籤迭代與的結合使用,一行2條或一行多條顯示方法

s:iterator標籤迭代與的結合使用,一行2條或一行多條顯示方法

一個jsp頁面,從後臺獲得集合,在頁面用s:iterator遍歷集合,一行顯示3條。格式如下:


1    2   3

4    5   6

7    8    9

用法如下

<table>
					<s:iterator value="smallBoards" status="count">
					
						  <s:if test="#count.index%3==0||#count.first">        
            <tr>            
        </s:if> 
						<td><a href="#"><s:property value="name" /></a></td>
					</s:iterator>
					 <s:if test="#count.index%2!=0||#count.last">        
            </tr>            
        </s:if> 
			</table>

這裡用count.index來獲取下標,一行顯示三條資料的格式為 

<s:if test="#count.index%X==0||#count.first">   <tr>     </s:if> 

<s:if test="#count.index%X-1!=0||#count.first">   <tr>     </s:if> 

X為一行顯示個數

註釋:

int getCount(); 迭代元素個數
int getIndex(); 迭代元素當前索引
boolean isEven() 當前迭代元素索引是否為偶數; 
boolean isOdd() 當前迭代元素索引是否為奇數; 
boolean isLast() 是否為最後一條元素; 
boolean isFirst() 是否為第一條元素。 

不懂可以留言。