Configuration config = new Configuration();
try {
config.setDirectoryForTemplateLoading(new File("bin/template"));
// 编码设置1
config.setDefaultEncoding("UTF-8");
Template template = config.getTemplate("add.jsp");
// 编码设置2
template.setEncoding("UTF-8");
config.setObjectWrapper(new DefaultObjectWrapper());
Map<String, Object> map = new HashMap<String, Object>();
map.put("className", "className");
map.put("columnDescribe", "columnDescribe");
map.put("columnName", "columnName");
map.put("action", "add");
map.put("title", "title");
List<String> columns = new ArrayList<String>();
columns.add("a");
columns.add("a");
columns.add("a");
columns.add("a");
map.put("columns", columns);
// 编码设置3
Writer out = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream("test.jsp"), "UTF-8"));
template.process(map, out);
out.flush();
} catch (Exception e) {
e.printStackTrace();
}
freemarker 设置编码
最新推荐文章于 2019-08-04 14:47:56 发布