freemarker之include指令
1、父页面ftl
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>学生信息</title>
</head>
<body>
<#include "/inc/top.ftl"/>
姓名:${student.studentName}
性别:${student.studentSex}
年龄:${student.studentAge}
生日:${(student.studentBirthday)?string("yyyy-MM-dd")}
地址:${student.studentAddr}
QQ:${student.studentQQ}
<#if student.studentAge lt 12>
${student.studentName}不是一个初中生
<#elseif student.studentAge lt 15>
${student.studentName}不是一个高中生
<#elseif student.studentAge lt 18>
${student.studentName}不是一个大学生
<#else>
${student.studentName}是一个大学生
</#if>
</body>
</html>
2、子页面ftl
<h1>欢迎,进入学生管理系统!</h1>
3、测试方法
Map<String,Object> root = null;
/**
*
* @Title:testStudent
* @Description:
* @param:
* @return: void
* @throws
*/
@Test
public void testStudent()
{
//创建数据模型
root = new HashMap<String,Object>();
root.put("student", new Student("张三丰","男",16,new Date(1988-12-12),"湖北省武汉市武昌洪山区",78451214));
student("student.ftl");
studentFile("student.ftl","student1.html");
}
/**
*
* @Title:student
* @Description:
* @param:@param name
* @return: void
* @throws
*/
private void student(String name)
{
ft.printFtl(name,root);
}
/**
*
* @Title:studentFile
* @Description:
* @param:@param name
* @param:@param fileName
* @return: void
* @throws
*/
private void studentFile(String name,String fileName)
{
ft.printFile(name, root, fileName);
}
4、生成HTML页面代码
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>学生信息</title>
</head>
<body>
<h1>欢迎,进入学生管理系统!</h1>
姓名:张三丰
性别:男
年龄:16
生日:1970-01-01
地址:湖北省武汉市武昌洪山区
QQ:78,451,214
张三丰不是一个大学生
</body>
</html>