惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

爱范儿
爱范儿
Know Your Adversary
Know Your Adversary
Google DeepMind News
Google DeepMind News
A
Arctic Wolf
P
Privacy & Cybersecurity Law Blog
云风的 BLOG
云风的 BLOG
Stack Overflow Blog
Stack Overflow Blog
V
Visual Studio Blog
Project Zero
Project Zero
L
LangChain Blog
N
News and Events Feed by Topic
博客园 - Franky
Last Week in AI
Last Week in AI
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
T
The Blog of Author Tim Ferriss
宝玉的分享
宝玉的分享
Scott Helme
Scott Helme
T
The Exploit Database - CXSecurity.com
P
Proofpoint News Feed
Blog — PlanetScale
Blog — PlanetScale
www.infosecurity-magazine.com
www.infosecurity-magazine.com
W
WeLiveSecurity
月光博客
月光博客
博客园_首页
美团技术团队
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
腾讯CDC
Latest news
Latest news
WordPress大学
WordPress大学
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Spread Privacy
Spread Privacy
Attack and Defense Labs
Attack and Defense Labs
量子位
L
LINUX DO - 热门话题
C
CERT Recently Published Vulnerability Notes
Webroot Blog
Webroot Blog
L
Lohrmann on Cybersecurity
aimingoo的专栏
aimingoo的专栏
T
Troy Hunt's Blog
Security Latest
Security Latest
小众软件
小众软件
Cloudbric
Cloudbric
Hacker News: Ask HN
Hacker News: Ask HN
S
Secure Thoughts
雷峰网
雷峰网
T
Threat Research - Cisco Blogs
H
Hacker News: Front Page
IT之家
IT之家
Simon Willison's Weblog
Simon Willison's Weblog

博客园 - blueKnight

Java根据WSDL生成request的SOAP报文模板 【转】HttpClient使用Post和Get提交参数 Java解析Soap XML HttpClient示例 【转】C++标准库和标准模板库 dotNetFrameWork 3.5SP1离线安装 笔记本电脑win7创建WIFI热点 【转】Oracle免客户端For .Net(增加分析Devart和DataDirect) 【转】ORA-00257 archiver error. 错误的处理方法 数学表达式与二叉树 FIREFOX不支持font-family: webdings;怎么办? "5","6"排序上下箭头问题 【转】Eclipse插件开发之基础篇(1) 插件开发的基础知识 http MIME大全 在iframe里的页面编写js,实现在父窗口上创建动画效果展开和收缩的div(不变动iframe父窗口代码) 转:用XML编写EXCEL文件 【网摘】BI系统(Business Intelligence) js获取周.html 关于j2ee工程发布到was上后,部分更新,例修改web.xml配置文件不起作用的原因解析 SSI(Struts2+Spring2+IBatis)代码生成器(纯Java版)
FreeMarker示例
blueKnight · 2011-11-17 · via 博客园 - blueKnight

<#macro greet person,website>
Hello ${person}! Your Website is ${website}.
</#macro>
<html>
<head>
<title>Hello World</title>
</head>
<body>
<@greet person="老紫竹" website="www.java2000.net"/>
<br />
${message}
<br />
编号:${est.id}<br>
名称:${est.name}
<table>
<#list listDatas as map>
<tr>
<td>${map.id}</td>
<td>${map.name}</td>
<td>${map.score}</td>
</tr>
</#list>
</table>
</body>
</html>

package com.freemarker;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import freemarker.template.Configuration;
import freemarker.template.Template;

public class TestFreeMarker {

    private Configuration cfg;

    public Configuration getCfg() {
        return cfg;
    }

    public void init() throws Exception {
        cfg = new Configuration();
        cfg.setDirectoryForTemplateLoading(new File("bin/com/freemarker"));
    }

    /**
     * 
@param args
     * 
@throws Exception 
     
*/
    public static void main(String[] args) throws Exception {
        TestFreeMarker obj = new TestFreeMarker();
        obj.init();
        //
        List<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();
        HashMap<String, Object> dataMap = new HashMap<String, Object>();
        dataMap.put("id", "1");
        dataMap.put("name", "张三");
        dataMap.put("score", 95);
        list.add(dataMap);
        dataMap = new HashMap<String, Object>();
        dataMap.put("id", "2");
        dataMap.put("name", "李四");
        dataMap.put("score", 88);
        list.add(dataMap);
        dataMap = new HashMap<String, Object>();
        dataMap.put("id", "3");
        dataMap.put("name", "王五");
        dataMap.put("score", 72);
        list.add(dataMap);
        Entity est = new Entity();
        est.setId(99);
        est.setName("dingzh@zbiti.com");
        //
        Map<String, Object> root = new HashMap<String, Object>();
        root.put("listDatas", list);
        root.put("est", est);
        root.put("message", "My first test freemarker...");
        //
        Template t = obj.getCfg().getTemplate("TestFreeMarker.ftl");
        Writer out = new OutputStreamWriter(new FileOutputStream("TestFreeMarker.html"), "GBK");
        t.process(root, out);
        out.flush();
        out.close();
        System.out.println("Successfull................");
    }

}

View Code Entity

package com.freemarker;

public class Entity {
    private int id;
    private String name;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

posted @ 2011-11-17 17:17  blueKnight  Views(1270)  Comments()    收藏  举报