2016-05-28 45 views
0

我有我需要的FreeMarker在FreeMarker的

final Map<String,Map<String,List<Person>>> root = fillMap(); 

遍歷爲了簡化想象這是一種分類的我哪裏有「大陸」,「國家」,下面的數據結構「人穿越嵌套的HashMap 」,其中人是

class Person{ 
    String name; 
    String id; 
} 

如果您想了解更多的澄清:

你可以在Java中(重點變種名稱)執行以下操作

Map<String,List<Person>> countriesForContinent = root.get(「Africa」); 

List<Person> personsForCountry = countriesForContinent.get(「Kenya」); 

在FreeMarker中,我需要能夠列出地圖中的每個大陸;然後對每個大陸,每個國家;然後爲每個國家,每個人。

我的HTML基本上是一些標籤(每個洲一個),每個選項卡上,我有全國部分,每個部分我列出屬於這個國家的人。

困難

我有列表標籤內所發生的困難。我知道例如root as continent沒有意義;但我不知道如何解決它。

<#list root as continent > 
    ${continent} 
    <#list continent as country > 
    ${country} 
    <#list country as person > 
     ${person.name} ${person.id} 
    </#> 
    </#> 
</#> 
+1

你對我們有什麼期望? –

+0

到目前爲止您嘗試過哪些方面,以及您遇到困難的具體位置? – Mureinik

+0

它看起來不像我的java問題。如果是這樣,你可以使用keySet作爲例子。 –

回答

0

在FreeMarker的模板,你不能列出Map -s,只有自己的密鑰(或它們的值)。所以你會有這樣的事情:

<#list root?keys as continentName> 
    ${continentName} 
    <#list root[continentName] as country > 
    ... 
    </#list> 
</#list>