zoukankan      html  css  js  c++  java
  • JavaFreemarker01快速上手

    在主类中

     1 package com.zhang;
     2 
     3 import java.io.IOException;
     4 import java.io.OutputStreamWriter;
     5 import java.util.HashMap;
     6 import java.util.Map;
     7 
     8 import freemarker.core.ParseException;
     9 import freemarker.template.Configuration;
    10 import freemarker.template.MalformedTemplateNameException;
    11 import freemarker.template.Template;
    12 import freemarker.template.TemplateException;
    13 import freemarker.template.TemplateNotFoundException;
    14 
    15 public class FreemarkerSimple1 {
    16     public static void main(String[] args) throws TemplateNotFoundException, MalformedTemplateNameException, ParseException, IOException, TemplateException {
    17         //创建核心配置对象
    18         Configuration config=new Configuration(Configuration.VERSION_2_3_31);
    19         //设置加载目录
    20         config.setClassForTemplateLoading(FreemarkerSimple1.class, "");
    21         //得到模板对象
    22         Template t= config.getTemplate("simple1.ftl");
    23         //创建数据
    24         Map<String,Object> data=new HashMap<String, Object>();
    25         data.put("site", "百度");
    26         data.put("url", "http://www.baidu.com");
    27         //产生输出
    28         t.process(data, new OutputStreamWriter(System.out));
    29     }
    30 }

    在ftl中:

    ${site}-${url}

    结果:

    百度-http://www.baidu.com

  • 相关阅读:
    详解Android Intent
    【JAVA EE企业级开发四步走完全攻略】
    撼动IT界的10大编程语言
    System.getProperty() 常用值
    Android List,Adapter相关
    为程序员量身定制的12个目标
    java 算法数据
    JAVA基础之理解JNI原理
    Java 工厂模式
    linux下C语言读取网卡MAC地址
  • 原文地址:https://www.cnblogs.com/tilyougogannbare666/p/14465608.html
Copyright © 2011-2022 走看看