Freemark上传

package com.axt.test;


import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;


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


public class FreeMarker {


public static void main(String[] args) {
// 通过Freemaker的Configuration读取相应的ftl
Configuration cfg = new Configuration();
try {
// 设定去哪里读取相应的ftl模板文件
            cfg.setClassForTemplateLoading(this.getClass(), "/ftl");
// 在模板文件目录中找到名称为name的文件
Template template = cfg.getTemplate(name);

// Build the data-model
Map<String, Object> data = new HashMap<String, Object>();
data.put("message", "Hello World!");


//List parsing 
// <td width="33%">检测单位:${reporthead.inspectionunit}</td>
//            <td width="33%">检测人:${reporthead.username}</td>
//            <td width="33%">被检测单位:${reporthead.detectionunit}</td>
            
Persion1 persion = new Persion1();
persion.setName("1");
data.put("reporthead", persion); 
data.put("datareportName", "任务漏洞详述");
// Console output
Writer out = new OutputStreamWriter(System.out);
template.process(data, out);
out.flush();
// File output
String path = "D:\\workspace\\leakscan\\WebRoot\\upload\\ReportExp" + "\\"+ "HTML" + "\\2-2css.html"  ;
Writer file = new FileWriter (new File(path));
template.process(data, file);
file.flush();
file.close();

} catch (IOException e) {
e.printStackTrace();
} catch (TemplateException e) {
e.printStackTrace();
}
}




}


class Persion1{

public String name;


public String getName() {
return name;
}


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


}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值