zoukankan      html  css  js  c++  java
  • freemarker之include指令

    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>
    


  • 相关阅读:
    php filter 安全过滤函数
    python常用快捷键
    【python】详解time模块功能asctime、localtime、mktime、sleep、strptime、strftime、time等函数以及时间的加减运算
    linux VIM基本命令
    vim常用命令总结 (转)
    sklearn中的交叉验证(Cross-Validation)
    scikit-learn 0.18中的cross_validation模块被移除
    python logging模块
    随机森林参数理解与调优
    kaggle 欺诈信用卡预测——Smote+LR
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13315080.html
Copyright © 2011-2022 走看看