freemarkerutils.java
来自「anewssystem新闻发布系统集成使用了spring hibernate f」· Java 代码 · 共 65 行
JAVA
65 行
package anni.tools;
import java.io.*;
import java.util.*;
import freemarker.template.*;
public class FreemarkerUtils {
public static void process(String templatePath,
Map model,
String destDirPath,
String destFileName) throws Exception {
process(templatePath, model, destDirPath, destFileName, "UTF-8");
}
public static void process(String templatePath,
Map model,
String destDirPath,
String destFileName,
String encoding) throws Exception {
Configuration cfg = new Configuration();
cfg.setDirectoryForTemplateLoading(new File("."));
cfg.setObjectWrapper(new DefaultObjectWrapper());
Template template = cfg.getTemplate(templatePath, encoding);
File destDir = new File(destDirPath);
if (!destDir.exists()) {
destDir.mkdirs();
}
File destFile = new File(destDir, destFileName);
Writer out = new OutputStreamWriter(new FileOutputStream(destFile), encoding);
template.process(model, out);
out.flush();
out.close();
}
public static void process(String templatePath,
Map model,
String destDirPath,
String destFileName,
String encoding,
Locale locale) throws Exception {
Configuration cfg = new Configuration();
cfg.setLocale(locale);
cfg.setDirectoryForTemplateLoading(new File("."));
cfg.setObjectWrapper(new DefaultObjectWrapper());
Template template = cfg.getTemplate(templatePath, encoding);
File destDir = new File(destDirPath);
if (!destDir.exists()) {
destDir.mkdirs();
}
File destFile = new File(destDir, destFileName);
Writer out = new OutputStreamWriter(new FileOutputStream(destFile), encoding);
template.process(model, out);
out.flush();
out.close();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?