67,512
社区成员
发帖
与我相关
我的任务
分享
private Configuration conf;
public void setFreeMarkerConfigurer(
FreeMarkerConfigurer freeMarkerConfigurer) {
//spring的FreeMarkerConfigurer
this.conf = freeMarkerConfigurer.getConfiguration();
}
@Transactional(readOnly = true)
public void index(CmsSite site, String tpl, Map<String, Object> data)
throws IOException, TemplateException {
long time = System.currentTimeMillis();
File f = new File(getIndexPath(site));
File parent = f.getParentFile();
if (!parent.exists()) {
parent.mkdirs();
}
Writer out = null;
try {
out = new OutputStreamWriter(new FileOutputStream(f), UTF8);
Template template = conf.getTemplate(tpl);
template.process(data, out);
} finally {
if (out != null) {
out.flush();
out.close();
}
}
time = System.currentTimeMillis() - time;
log.info("create index page, in {} ms", time);
}