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

  • 相关阅读:
    cocoapods 命令
    开发常用
    ios 定位
    LoadingView
    自定义cell右侧 多按钮
    cocoaPods
    AFNetWorking
    iphone自定义铃声
    升级为iOS9后,默认请求类型为https,如何使用http进行请求会报错(引用他人的)
    理解c语言中的指针
  • 原文地址:https://www.cnblogs.com/tilyougogannbare666/p/14465608.html
Copyright © 2011-2022 走看看