最近一段时间在整一个项目,里面用到很多知识点,其中有 freemarker,以前没用过,花一段时间来研究。
使用 freemarker 根据模板生成静态页面时,经常会在页面中显示数值,List或者Map形式的。
下面的代码是我在项目中运行成功的代码, 欢迎高手指点优化。
遍历List:(topTenDocList为10篇文章的List, docDocumen为文章对象)
<#list topTenDocList?if_exists as docDocument> <tr> <td>${docDocument.urltitle}</td> <td>${docDocument.urltime}</td> </tr> </#list>
遍历Map:(personMap为人员Map,键值对为姓名:年龄)
<#list personMap?keys as mapkey> ${mapkey}:${personMap[mapkey]} </#list>
${personMap[mapkey]}这样遍历Map时,键只能是String类型的。
本文分享了Freemarker模板引擎的实际应用案例,包括如何在项目中利用Freemarker将List和Map数据类型渲染到静态页面的具体代码实现。
2363

被折叠的 条评论
为什么被折叠?



