JAVA使用Freemarker生成静态文件中文乱码

1.指定Configuration编码

Configuration freemarkerCfg = new Configuration();
freemarkerCfg.setEncoding(Locale.getDefault(), "UTF-8");

2.指定template编码

Template template = freemarkerCfg.getTemplate(templatePath,"UTF-8");            
template.setEncoding("UTF-8");

3.Controller里面

response.setCharacterEncoding("UTF-8");

第三个配置很重要,找了半天freemarker的编码配置,结果问题不是freemarker上,而是在response上。

更详细的解释请看 :  http://kun587.org/post/2013/05/25/169.html

原文地址:https://www.cnblogs.com/liuchao102/p/4425220.html