1. Traverse map types
1. First look at the background java program
Java code
Copy the code code as follows:
Map<String,String> paramValues=new HashMap<String, String>();
***
*** The intermediate assignment operation is omitted
***
data.put("paramValues", paramValues); // Pass values to velocity
2. Get the key and value of this map from the front-end velocity template file
Java code
Copy the code code as follows:
#foreach($param in ${paramValues.keySet()})
<tr>
<th>$param</th>
<td>${paramValues.get($param)}</td>
</tr>
#end
2. Traverse the List type
1. First look at the background java code
Java code
Copy the code code as follows:
List<Saler> salerList=new ArrayList<Saler>();
***
***The intermediate assignment operation is omitted
***
data.put("salerList", salerList);//pass value to velocity
2. Look at the code in the velocity template again
Copy the code code as follows:
#foreach($sal in ${salerList})
$sal.name
#end