Freemarker list (length, traversal, subscript, nesting, sort)
1. Freemarker Gets the size of the list:
Java
arraylist<string> list = new arraylist<string> ();
Freemaker
${list?size}
2. List traversal:
< #list animals as being>
<tr>
<td>${being.name}${being.price}<td>
</tr>
</#list >
3. Traverse the Map
< #list Map?keys as k>
<option value= "${k}" >${map[k]}</option>
</#list >
The subscript number in the 4.list traversal:
_index is a property of list
< #list list as a>
${a_index}
</#list >
5. Take the value of the first element of the list
${list[i]}
Nesting is preceded by parentheses, as follows, the string becomes a list, and the value of the element i is taken
${(Str?split (",")) [i]}
6. Nesting of list:
< #list jssklist as jsskvo>
< #list kclist as kcvo>
< #if kcvo.kch=jsskvo.kch> (KCVO with number and name, and JSSKVO only number)
${KCVO.KCM}
</#if >
</#list >
</#list >
7. List sort:
Ascending. Sort_by ()
< #list list?sort_by ("field") as X>
</#list >
Descending. Sort_by ()? reverse
< #list list?sort_by ("field")? Reverse as X>
</#list >
8.item_has_next,size using:
< #list userlist as user>
< #if!user_has_next>
Total ${userlist?size} The last user is: ${user.username}
</#if >
</#list >
Freemarker Collection Traversal