I Karte erstellt haben, die die Postadresse enthält, die schließlich zu homeaddress Karte übergeben wird .Siehe die folgenden CodeWie mithilfe von Variablendeklaration Karte Geschwindigkeitsvorlagendatei zuzugreifen
Map map1 = new HashMap();
map1.put("address", "address1 trinity");
map1.put("address2", "addressmg road");
map1.put("city", "bangalore");
map1.put("state", "karnataka");
Map map2 = new HashMap();
map2.put("postal_address",map1);
VelocityContext context = new VelocityContext();
context.put("homeAddress",map2);
Template Code:
Variable Declaration:
#set ($PostalAddress_Address2 ="address2")
#set ($PostalAddress_City ="city")
#set ($PostalAddress_State ="state")
Iterating the Map:
#set($tocList=${homeAddress.postal_address})
$tocList.get($PostalAddress_Address2)
$tocList.get($PostalAddress_State)
$tocList.get($PostalAddress_City)
Der obige Code funktioniert fine.But, wenn ich die Variable Erklärung für postal_address_main als postal_address ersetzen dann nicht seine Arbeits
#set ($postal_address_main ="postal_address")
#set($tocList=${homeAddress.postal_address_main })
Irgendwelche Vorschläge dazu? Wie ersetze ich die Variablendeklaration beim Abrufen des Wertes aus der Map?
Mögliche Antwort hier http://stackoverflow.com/questions/2344341/reference-a-map-by-name-within-velocity-template?rq=1 – jira
Dank Jira für diesen Hinweis..aber ich habe nicht wo um die Methode in meinem Fall zu schreiben –
Dank Jira kann ich das obige Problem beheben –