Its a normal thing that we get confused between looping when we are using list, hashmap or array in freemarker .As the syntax differ for each things in freemarker. It also happens that when we want to generate JSON from java collection, we need to append comma on each iteration except the last one.Identifying an last iteration is also an issue when we use freemarker. Its not much difficult, its just we are not concentrating on syntax.
So lets look on the syntax of each one.
Iterating Array or Sequence(generally its any type of List) in freemarker
-
<#list ArrayOrListOfusers as user>
<li>${user}
</#list>
Iterating Hashmap in freemarker
When we are dealing with hashmap type of object, There are 2 values getting stored in side an item of hashmap.There are some technical scenarios in which we need only list values , We need only key of hashmap etc...
-
<#list HashMap as keyItem,valItem>
<li>${key}=${val}
</#list>
0 comments:
Post a Comment