有用freemaker生成静态网页的案例教程吗?求教。
[code="java"]public boolean createDoc(Map dataMap, String outUrl, String modelUrl,String modelName) {
// 设置模本装置方法和路径,FreeMarker支持多种模板装载方法。可以从servlet,classpath,数据库装载,
configuration.setClassForTemplateLoading(this.getClass(), modelUrl);
Template t = null;
// 输出文档路径及名称
File outFile = new File(outUrl);
Writer out = null;
try {
//装载模板
t = configuration.getTemplate(modelName);
t.setEncoding("utf-8");
out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), "utf-8"));
t.process(dataMap, out);
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
} catch (TemplateException e) {
e.printStackTrace();
return false;
}finally{
try {
if (out!=null) {
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}[/code]
先加载模板,后生成文档或者你的模板文件!
可以看看Shop++ 里面应该有你想要的
下载的Freemarker压缩包中有个文件夹有例子,里面很详细的,包括sevelt+Freemarker的,纯Freemarker的,Freemarker+MVC框架(struts有,其他的没看了)的