freemarker list 顯示 JSON 迴圈資料的範例
FreeMarker 是一個基於 Java 的模板引擎,在 Freemarker 在 Spring boot 上的配置並加入 Spring Security Tag 與 Spring Boot 使用 Freemarker 開發 Java Tag 客製標籤 分別有說明在 Spring Boot 中該如何設定與引入使用。
資料常會有迴圈需要顯示,例如下面的 JSON 資料。
{ "Education" : {"cssiCon":"fas fa-book mr-1","value":"B.S. in Computer Science from the University of Tennessee at Knoxville"}, "Location" : {"cssiCon":"fas fa-map-marker-alt mr-1","value":"Taipei, Taiwan"}, "Skills" : {"cssiCon":"fas fa-pencil-alt mr-1","value":"UI Design, Coding, Javascript, PHP, Node.js"}, "Notes" : {"cssiCon":"far fa-file-alt mr-1","value":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam fermentum enim neque."}}
當上面的資料由後台回傳在 aboutMe
的變數中,若要取得 Education, Location, Skills, Notes 這些主要關鍵的資料時,使用 freemarker list方法如下:
<#if aboutMe??> <#list aboutMe as Key, value> <#list value as k,v> <#if k=="cssiCon"> <strong><i class="${v}"></i> ${Key}</strong> </#if> <#if k=="value"> <p class="text-muted">${v}</p> </#if> </#list> <hr> </#list> </#if>
你必須 登入 才能發表評論。