List list = new ArrayList();
for(int i=0;i<10;i++){
UserInfo info = new UserInfo();
info.setUserId(i);
info.setUserName("username"+i);
list.add(info);
}
map.put("person",list);
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf8">
</head>
<body>
<p>We have these animals:
<table border=1>
<tr><th>Name<th>Price
<#list person as being>
<tr>
<td>
<#if being.userId = 1><b></#if>
${being.userId}
<#if being.userName="userName1"></b></#if>
<td>${being.userName} </td>
</#list>
</table>
</body>
</html>
本文展示了一个使用Freemarker模板引擎的例子,其中包括了如何在Java中填充数据并将其渲染到HTML页面上。通过这个例子可以看到如何定义一个包含列表的模型,并在模板中遍历这些数据。
253

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



