<for>
Iterate over collection
Iterate over collection you can use the Ognl expression of collection to get the properties and methods of variable value in context or session.
value(required) Get collection of variable, can also get the Ognl collection of the variable
valueScope(optional) The scope of the variable Property context:Get variable from context(default) session:Get variable from session
var(required) Set the variable of each element
status(optional) Set the variable of loop info Symbol describe count loop count index current loop index isFirst current loop is first isLast current loop is last
trim(optional) Whether to retain the output value of the front and back blank characters Property false:yes(default) true:no(Including the newline)
delimiter(optional) delimiter of loop
test(optional) Using Ognl to judgment the conditions, The result is true, then run the current loop, The result is false, not run Symbol ==:equal !=:not equal &&:and ||:or
duplicate(optional) Whether the output of duplicate content Property true:duplicate content is still output(default) false:duplicate content is no longer output
Get the collection from value and set it to var, var is each element of iterate object.
Set a list and iterate over it.
Result
Tip: The iterate each element, the mouse is placed above, or selected, can show the value.
Set a Map, and each element has 2 attributes, key and value.
Result
Symbol describe count size of collection index current index isFirst current is first isLast current is last
Example:
Result
You can set test, enter the Ognl expression, if the expression returned is true, current loop execute, then returned is false. current loop not execute.
We initialize a List, which is put into 3 Book objects, The Book object contains three fields, int:id, String:name, Double:price.
Set the action in the template to ForTagAction for the code prompt
Loop when price is greater than 50.
Result, loop only price elements greater than 50
Tip: The loop element can view its Ognl value.
Trim is to judge whether to retain the output value of the front and back blank characters, the default false, that is to say, output all characters.
The following 2 output methods, one default trim="false", the other trim="true".
As you can see, the first method outputs as it is, including front and back spaces and newline characters, while the other removes spaces and newline characters.
The separator between the loop output. If a delimiter is specified, the output elements are separated by separator.
Sets the parameter type and parameter name of the method, and the parameter is separated by ","
Result
Sometimes the output may be the same. If you don't want to repeat the same output, you can set it: duplicate="false",The same content is not repeated default is duplicate="true"。
There is no need to repeat output of import.
Result