解决办法一:通过修改配置文件freemarker.properties,修改默认编码:
locale=zh_CN
default_encoding=gbk
number_format=#
date_format=yyyy-MM-dd
time_format=HH:mm:Ss
datetime_format=yyyy-MM-dd HH:mm:Ss
还有1个办法 在contentType
里设置value为text/html;charset=UTF-8"
<!-- FreeMarker视图解析器 -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.freemarker.FreeMarkerView" />
<property name="contentType" value="text/html;charset=UTF-8" />
<property name="cache" value="false" />
<property name="viewNames" value="*.ftl" />
<property name="suffix" value="" />
<property name="order" value="2" />
</bean>
解决办法二:通过spring或其他第三方工具配置:
<bean id="freemakerCongfig"
class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
<property name="templateLoaderPath">
<value>/WEB-INF/web/</value>
</property>
<property name="freemarkerSettings">
<props>
<prop key="defaultEncoding">gbk</prop>
</props>
</property>
</bean>