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

推荐订阅源

Stack Overflow Blog
Stack Overflow Blog
WordPress大学
WordPress大学
罗磊的独立博客
S
Secure Thoughts
Schneier on Security
Schneier on Security
博客园 - Franky
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
爱范儿
爱范儿
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Hacker News: Ask HN
Hacker News: Ask HN
PCI Perspectives
PCI Perspectives
Google DeepMind News
Google DeepMind News
S
Security Affairs
SecWiki News
SecWiki News
博客园 - 聂微东
Security Archives - TechRepublic
Security Archives - TechRepublic
Google Online Security Blog
Google Online Security Blog
H
Heimdal Security Blog
S
Security @ Cisco Blogs
Engineering at Meta
Engineering at Meta
C
CXSECURITY Database RSS Feed - CXSecurity.com
Cloudbric
Cloudbric
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
V
Visual Studio Blog
P
Proofpoint News Feed
Project Zero
Project Zero
T
Threat Research - Cisco Blogs
Webroot Blog
Webroot Blog
Blog — PlanetScale
Blog — PlanetScale
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
W
WeLiveSecurity
Last Week in AI
Last Week in AI
月光博客
月光博客
Microsoft Azure Blog
Microsoft Azure Blog
M
MIT News - Artificial intelligence
有赞技术团队
有赞技术团队
S
Securelist
GbyAI
GbyAI
Application and Cybersecurity Blog
Application and Cybersecurity Blog
C
CERT Recently Published Vulnerability Notes
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Cyberwarzone
Cyberwarzone
B
Blog RSS Feed
P
Palo Alto Networks Blog
H
Hacker News: Front Page
D
Docker
雷峰网
雷峰网
Latest news
Latest news
Microsoft Security Blog
Microsoft Security Blog

博客园 - 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()    收藏  举报