在java端加入如下代码
freemarkerCfg.setEncoding(Locale.getDefault(), "UTF-8");
template.setEncoding("UTF-8");
在模板页上确保有如下代码:
<meta http-equiv="Content-type" content="text/html; charset=UTF-8">
OK!解决了!
本文介绍如何在Java端使用Freemarker时正确设置UTF-8编码以避免字符乱码问题。通过配置Freemarker和模板文件的编码方式,确保中文等非ASCII字符能正常显示。
在java端加入如下代码
freemarkerCfg.setEncoding(Locale.getDefault(), "UTF-8");
template.setEncoding("UTF-8");
在模板页上确保有如下代码:
<meta http-equiv="Content-type" content="text/html; charset=UTF-8">
OK!解决了!

被折叠的 条评论
为什么被折叠?