Wie Sie access-Karte in das velocity-template-Datei

wenn ich an einem Map<String,String> im velocity-template-Datei, und wenn Sie versuchen, zu drucken, die Werte von der Karte sortiert werden (auf der Grundlage von ASCII-Werten).

Mache ich wie folgt:

dies ist mein velocity-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);

Ausgabe:

 <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 sortiert? Ich möchte auf print-anzeigen, wie es ist.

InformationsquelleAutor ved | 2012-04-01

Schreibe einen Kommentar