[英]freemarker template syntax spring boot
我有一個創建哈希圖的 springboot 應用程序。 我想創建一個表,它有一個標題和多行(地圖中的每個值一個)。 以下代碼返回 ISE:
出現意外錯誤(類型=內部服務器錯誤,狀態=500)。 無法解析 URL [toDoListView.ftl] 的 FreeMarker 模板; 嵌套異常是 freemarker.core.ParseException:第 47 行第 37 列模板“toDoListView.ftl”中的語法錯誤:遇到“>”,但期待以下之一:“..”“.. ”“as”“。” "[" "(" "?" "!" "??" "+" "-" " " "/" "%" "!=" "=" "==" ">=" ">"
第 47 行是:<#list itemMap>
<#if itemMap??>
<table class="table table-bordered">
<#list itemMap>
<thead>
<tr>
<th></th>
<th>Item1</th>
<th>Item2</th>
<th>Item3</th>
</tr>
</thead>
<#item?keys as key>
<#if !itemMap?values[key_index].done>
<tbody>
<tr>
<td id="checkbox_column" width="40">
<input type="checkbox" name="im" value="${key}">
</td>
<#if itemMap?values[key_index].color == "BLUE">
<td>${itemMap?values[key_index].blue}</td>
<#elseif itemMap?values[key_index].color == "RED">
<td>${itemMap?values[key_index].red}</td>
</#if>
</tr>
</tbody>
</#if>
</#item?keys>
</table>
<#else>
No Items!
</#list>
我不確定是什么導致了這個錯誤。 我試圖按照表格 2 下列出的示例進行操作: http : //freemarker.org/docs/ref_directive_list.html
當然是因為您使用的是 2.3.23 之前的 FreeMarker 版本。 在 2.3.23 之前,您不能從#list
標簽中省略as
。 (稍后您還會有一些雜亂的部分,例如<#itemMap?keys as key>
或</#listy?keys>
,但我認為您可以解決這些問題。)
要檢查 FreeMarker 版本,請嘗試${.version}
(刪除語法錯誤的部分后)。 要增加來自 Spring BOM 的 FreeMarker 版本,請在 POM 的dependencyManagement
部分中覆蓋它。 就像是:
<dependencyManagement>
...
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.23</version>
<dependency>
...
</dependencyManagement>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.