标签:freemarker 变量
freemarker四种变量
1、简介说明
(1)数据模型中的变量:root中的变量
(2)模板中的变量:使用<#assign>定义的变量
(3)局部变量:在指令中的变量
(4)循环变量:在循环中的变量
2、使用说明
(1)数据模型中的变量:root中的变量
A Junit方法
@Test
public void testRoot()
{
root.put("age", "23");
studentPrint("tag.ftl");
}
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>freemarker root中的变量</title>
</head>
<body>
<#--freemarker数据模型中的变量-->
${age}
</body>
</html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>freemarker root中的变量</title>
</head>
<body>
23
</body>
</html>
(2)模板中的变量:使用<#assign>定义的变量
<#--freemarker模板中的变量-->
<#---此时模板中的变量的名称和模型中的变量名称一致,不覆盖,而是隐藏-->
<#assign age="56"/>
${age}
<#--使用.globals可以访问模型中的变量-->
${.globals.age}
56 23
<#--freemarker模板中的变量-->
<#---此时模板中的变量的名称和模型中的变量名称一致,不覆盖,而是隐藏-->
<#assign age="56"/>
${age}
<#--使用.globals可以访问模型中的变量-->
${.globals.age}
<#macro ageNum>
<#local age="45"/>
</#macro>
<@ageNum/>
${age}结果:
56 23 56
(4)循环变量:在循环中的变量
${age}
<#list 1..10 as age>
${age}
</#list>
${age}56 1 2 3 4 5 6 7 8 9 10 56
标签:freemarker 变量
原文地址:http://blog.csdn.net/you23hai45/article/details/30124761