首次在JAVA项目中使用FreeMarker并在堆栈上配置中文字符。FreeMarker无法显示汉字
我尝试了很多例子来修复下面的代码,但它仍然无法做到。
// Free-marker configuration object
Configuration conf = new Configuration();
conf.setTemplateLoader(new ClassTemplateLoader(getClass(), "/"));
conf.setLocale(Locale.CHINA);
conf.setDefaultEncoding("UTF-8");
// Load template from source folder
Template template = conf.getTemplate(templatePath);
template.setEncoding("UTF-8");
// Get Free-Marker output value
Writer output = new StringWriter();
template.process(input, output);
// Map Email Full Content
EmailNotification email = new EmailNotification();
email.setSubject(subject);
.......
看到了一些示例请求,以对freemarker.properties进行更改,但我没有此文件。我只是导入.jar文件并使用它。
请告诉我该怎么做才能让它显示汉字。
是什么让你觉得它没有正确显示中文字符? – Raedwald
您的模板文件是否正确地使用了UTF-8编码? –
[Freemarker编码 - 重音字符处的问号]的可能重复(http://stackoverflow.com/questions/9559658/freemarker-encoding-question-marks-in-the-place-of-accented-characters) – Raedwald