struts2’s s:iterator can traverse any array, collection, etc. in the data stack. Here are some simple demos:
s:iterator tag has 3 attributes:
value: the iterated collection
id: the element in the specified collection The id
status is the index of the iterated element
1:jsp page definition element writing array or list
The printed result is: 1A2A3A4A5A
2: Index usage
If specified status, each iteration data has an instance of IteratorStatus, which has the following methods
1: #status.odd Whether the current element index is an odd number of rows 2: # status.even Is the current element index even? 3: #status.count How many elements are currently iterated 5: #status.first Whether the current element is the first value="#{"1":"a","2":"b"}" 3: traverse the data stack. Simple List class, 4: Traverse 2 lists;
Line
4: #status.index Current element index, starting from 0『#status.count=#status.index+1 』
6: #status.last Whether the current element is the last
7: #status.modules(int) Modulo the number of current rows
Current index It is an odd number:
Current element value:
s:iterator>
3: Traversing the map
value can be directly defined as:
Each element is separated by . The key and value between elements are separated by colons
value can also be the java.util.Map object in the data stack
The traversal is written as follows:
key :
value:
Of course both key and value You can use java's Object
List
class Attr{String attrName;String getAttrName(){return "123";}}
Of course value can also be written as value="%{label}" label can have. The operation
label's attribute List can be written as value="%{label.list}" which is equivalent to: getLabel().getList();
List
List
The elements of these two lists are one-to-one correspondence, one attrN corresponds to one attrV
index is :
attrName is :
attrName is :