日期:2014-05-20  浏览次数:20606 次

freemarker能否嵌套
freemarker模板中能否嵌入模板?就好象jsp页面中能嵌入另外一个jsp一样?

------解决方案--------------------
可以啊
------解决方案--------------------
正在学习中,顶一下了!
------解决方案--------------------
myTemplate.ftl

<#macro student name age>
大家好:我是${name},今年${age}岁.<#nested>
</#macro>
-------------------------
template.ftl
<#import "/src/macro/myTemplate.ftl" as my/>
<@my.student name="樊海" age="25">
123
</@my.student>
------解决方案--------------------

public class FreeMarkerTest {

public static void main(String[] args) throws Exception {
UpperDirective upper = new UpperDirective();
Map map = new HashMap();
map.put("upper", upper);
Template template = FreeMarkerUtil.getTemplate("src\\macro\\template.ftl");
File htmlFile = new File("src\\macro\\freemaker.htm");
Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(htmlFile)));
template.process(map, writer);
}
}