2016-08-14 15 views
0

我正在用Thymeleaf做我的第一個項目。我的大部分工作都完成了......除了下面這部分。在Thymeleaf中使用Dynamic key for hashMap,以及屬性

<img th:attrappend="src='file:///' + ${entryImageMap['__${entry.id}__']}"></img> 

這是我從Thymeleaf

org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating OGNL expression: "entryImageMap['83383894']" (template: "Report.html" - line 89, col 6) 

我已經試過微小變化得到的錯誤。這是我通過各種錯誤的方式取得的進展,仍然不清楚。

<img th:attrappend="src=file:///${entryImageMap.(entry.id)}"></img> 
<img th:attrappend="src=file:///${entryImageMap[__${entry.id}__]}"></img> 
<img th:attrappend="src='file:///' + ${entryImageMap[__${entry.id}__]}"></img> 
<img th:attrappend="src='file:///' + ${entryImageMap['__${entry.id}__']}"></img> 

回答

0

這工作:

<img th:attrappend="src='file:///' + ${data.entryImageMap.get('__${entry.id}__')}"></img> 

我做了假設entryImageMap的錯誤是在根。而在data對象內。

如果我正確使用了data.entryImageMap,上述情況幾乎不會有效。