Velocity displays detailed resolution of the methods of List and Map

  • 2020-04-01 02:12:59
  • OfStack

Traversing a map type

1. Look at the background Java program first
Java code


    Map<String,String> paramValues=new HashMap<String, String>();  
    ***  
    ***  The middle assignment is omitted   
    ***  
    data.put("paramValues", paramValues);//The value to velocity 

2. Fetch the key and value of this map from the velocity template file in the foreground
Java code

    #foreach($param in ${paramValues.keySet()})  
    <tr>  
        <th>$param</th>  
        <td>${paramValues.get($param)}</td>  
   </tr>  
    #end  

Traversing the List type

1. Look at the background Java code first
Java code


    List<Saler> salerList=new ArrayList<Saler>();  
    ***  
    *** The middle assignment is omitted   
    ***  
    data.put("salerList", salerList);//The value to velocity 

2. Now look at the code in the velocity template

    #foreach($sal in ${salerList})  
    $sal.name  
    #end  


Related articles: