, wenn ich eine Map<String,String>
in Geschwindigkeit Vorlage Datei übergeben, und wenn versuchen, die Werte der Karte zu drucken es sortiert (auf der Grundlage von ASCII-Werten).Zugriff auf Karte in Geschwindigkeit Template-Datei
ich tue, wie folgt:
das ist meine Geschwindigkeit Template-Datei ::
#set($tocList=${mapReference.mapValue})
#set($tocEntry="")
<div >
#foreach($tocEntry in $tocList.keySet())
<a href="#$tocEntry">$tocList.get($tocEntry)</a><br/>
#end
</div>
Mein Java-Code ist:
Map<String, String> map=new HashMap<String, String>();
Map<String,HashMap> m1=new HashMap<String, HashMap>();
\\values that we want to print in template file
map.put("sdfhfg", "Df lm");
map.put("chdgfhd", "gBc Jk");
map.put("dghjdhdf", "gI Ml");
m1.put("mapValue", (HashMap) map);
VelocityEngine velocityEngine = VelocityEngineFactory.getVelocityEngine();
VelocityContext context = new VelocityContext();
context.put("img",model);
context.put("mapReference",m1);
context.put("iterator", new IteratorTool());
Template t = velocityEngine.getTemplate("tocTemplate.vm");
StringWriter writer = new StringWriter();
t.merge(context , writer);
System.out.println(writer);
Ausgang ist:
<div>
<a href="#dghjdhdf">gI Ml</a><br/>
<a href="#chdgfhd">gBc Jk</a><br/>
<a href="#sdfhfg">Df lm</a><br/>
</div>
Warum diese Werte g und sortiert? Ich möchte die Karte so drucken, wie sie ist.
nicht die [link] (http://docs.oracle.com/javase/6/docs/api/java/util/TreeMap.html) –