Java XML Freemarker一个序列中有两个hashmap

Java XML Freemarker一个序列中有两个hashmap,java,c,xml,freemarker,Java,C,Xml,Freemarker,我想生成两个带有注释的C枚举。相应的数据存储在XML文件中 因此,我使用Java从XML数据中读取了两个标记,ID和Comment。ID和Comment存储在两个单独的hashmap中。这两个哈希映射都是(相同)对象的arraylist的一部分。我还有setter和getter函数。 我能够分别生成注释和ID。但是,我不能以相同的顺序生成ID和注释 **File 0:** Class example { private Map<String, String> idList

我想生成两个带有注释的C枚举。相应的数据存储在XML文件中

因此,我使用Java从XML数据中读取了两个标记,ID和Comment。ID和Comment存储在两个单独的hashmap中。这两个哈希映射都是(相同)对象的arraylist的一部分。我还有setter和getter函数。 我能够分别生成注释和ID。但是,我不能以相同的顺序生成ID和注释

**File 0:**
Class example {
   private Map<String, String> idList    = new HashMap<String, String>();
   private Map<String, String> cmtList   = new HashMap<String, String>();

   public Map<String, String> getIdList() {    
      return this.idList;
   };
   public Map<String, String> getCmtList() {    
      return this.cmtList;
  };
}

File 1:
List<example> Freemarker_arr = new ArrayList< example >();

public List< example > getXmlModes() {
    return Freemarker_arr;
}


File 2: 
<#list model.getXmlModes() as i>
<#list i.getIdList()?keys as id>
typedef enum 
{
   ${"ABC_ID" + id},            // This one works fine. Ids are generated.
} value_st;
</#list>
</#list>

<#list model.getXmlModes() as i>
<#list i.getCmtList()?keys as cmt>
typedef enum 
{
    ${cmt},                 // This one works also fine. Comments are generated.
} value_st;
</#list>
</#list>
代码:

问题: 我的代码有什么问题?

您应该只列出其中一个列表,同时按索引从另一个列表中获取元素。在您的例子中,列表类似于
someMap?键
,与此类似:

<#assign bKeys = bMap?keys>
<#list aMap?keys as aKey>
  Key from aMap: ${aKey}
  Key from bMap: ${bKeys[aKey?index]}
</#list>

来自aMap的密钥:${aKey}
来自bMap的键:${bKeys[aKey?index]}
关于你的代码有什么问题。如果将两个
#list
-s嵌套在一起,则将为外部列表的每个元素列出整个内部列表。

您应该只列出其中一个列表,同时通过索引从另一个列表中获取元素。在您的例子中,列表类似于
someMap?键
,与此类似:

<#assign bKeys = bMap?keys>
<#list aMap?keys as aKey>
  Key from aMap: ${aKey}
  Key from bMap: ${bKeys[aKey?index]}
</#list>

来自aMap的密钥:${aKey}
来自bMap的键:${bKeys[aKey?index]}
关于你的代码有什么问题。如果将两个
#list
-s嵌套在一起,则将为外部列表的每个元素列出整个内部列表

// Comment 1
// Enum 1

// Comment 1
// Enum 2

// Comment 2 
// Enum 1

// Comment 2 
// Enum 2
<#assign bKeys = bMap?keys>
<#list aMap?keys as aKey>
  Key from aMap: ${aKey}
  Key from bMap: ${bKeys[aKey?index]}
</#list>