答案已被找到:$ {帳戶[道具]},而不是$ {account.get(丙)}工作Freemarker的遍歷HashMap的鍵列表中的
帳戶是圖有相似
類型的列表//[{"id":"1","location":"warehouse1"},{"id":"2","location":"warehouse2"}]
ArrayList<HashMap<String, String>> t = m.t();
root.put("accounts", t);
Writer out = null;
try {
out = context.response.getWriter();
T.getViewTpl(tplName).process(root, out);
} catch (IOException | TemplateException ex) {
T.logger.error(T.class.getName(), ex);
} finally {
try {
out.close();
} catch (IOException ex) {
T.logger.error(T.class.getName(), ex);
}
}
它被呈現爲表格。一個帳戶一列,一個帳戶一列。下面的代碼不起作用。它是如何完成的?提前致謝!
<table>
<#list accounts as account>
<tr>
<#list account?keys as prop>
<td>${account.get(prop)}</td>
</#list>
</tr>
</#list>
</table>
Freemarker的錯誤是:
FreeMarker template error
The following has evaluated to null or missing:
==> account.get [in template "account.tpl" at line 14, column 23]
謝謝您回答! '用戶'是一個錯字。它已被糾正。但仍然無法工作。錯誤通過freemarker是:以下評估爲空或丟失: ==> account.keys [模板「account.tpl」在第13行,第24列] – Peter
如何將地圖傳遞到Java的ftl? – Niemand
粘貼這裏的代碼很難看。你能否看到更新的問題? – Peter