zoukankan      html  css  js  c++  java
  • freemaker:通过map方式替换字符串

    1. maven

    <dependency>
    <groupId>org.freemarker</groupId>
    <artifactId>freemarker</artifactId>
    <version>2.3.31</version>
    </dependency>

    2.
    import java.io.IOException;
    import java.io.OutputStreamWriter;
    import java.io.StringReader;
    import java.util.HashMap;
    import java.util.Map;
    
    import freemarker.template.Template;
    import freemarker.template.TemplateException;
    
    public class test01 {
    
    public static void main(String[] args) {
    try {
    Template tmp = new Template(null, new StringReader("name:${user};URL:${url};uname:${name}"), null);
    Map<String,String> map = new HashMap<String,String>();
    map.put("user", "crd");
    map.put("url", "www.baidu.com");
    map.put("name", "baidu");
    tmp.process(map, new OutputStreamWriter(System.out));
    } catch (IOException e) {
    e.printStackTrace();
    }catch (TemplateException e) {
    e.printStackTrace();
    }
    }
    
    }
    
    后台打印:
    
    name:crd;URL:www.baidu.com;uname:baidu

    import java.io.IOException;
    import java.io.OutputStreamWriter;
    import java.io.StringReader;
    import java.util.HashMap;
    import java.util.Map;

    import freemarker.template.Template;
    import freemarker.template.TemplateException;

    public class test01 {

    public static void main(String[] args) {
    try {
    Template tmp = new Template(null, new StringReader("name:${user};URL:${url};uname:${name}"), null);
    Map<String,String> map = new HashMap<String,String>();
    map.put("user", "crd");
    map.put("url", "www.baidu.com");
    map.put("name", "baidu");
    tmp.process(map, new OutputStreamWriter(System.out));
    } catch (IOException e) {
    e.printStackTrace();
    }catch (TemplateException e) {
    e.printStackTrace();
    }
    }

    }

    后台打印:

    name:crd;URL:www.baidu.com;uname:baidu

  • 相关阅读:
    Python可视化库Matplotlib绘图基础学习
    字典特征和文本特征数据抽取
    ipc_11_快乐 happy
    关于Scanf的返回值问题
    [转]网站性能测试总结
    C语言运算符优先级
    成员运算符(·)和指向结构体成员运算符(->)的区别
    c++抛出异常与栈展开(stack unwinding)
    What is a Delegate?
    1.2 Variables and Arithmetic Expressions
  • 原文地址:https://www.cnblogs.com/tiancai/p/14793407.html
Copyright © 2011-2022 走看看