Spring MVC使用Freemaker 中文乱码

直接附上关键代码:

<!-- freemarker config -->
	<bean id="freemarkerConfig"
		class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
		<property name="templateLoaderPath">
			<value></value>
		</property>
		<property name="freemarkerSettings">
			<props>
				<prop key="template_update_delay">0</prop><!-- 0为开发使用,正式使用时应大于3600 -->
				<prop key="defaultEncoding">UTF-8</prop>
				<prop key="locale">zh_CN</prop>
			</props>
		</property>
	</bean>

	<!-- View resolvers can also be configured with ResourceBundles or XML files. 
		If you need different view resolving based on Locale, you have to use the 
		resource bundle resolver. -->
	<bean id="viewResolver"
		class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
		<property name="cache" value="false" />
		<property name="prefix" value="" />
		<property name="suffix" value=".ftl" />
               <property name="contentType" value="text/html" />
<!-- if you want to use the Spring FreeMarker macros, set this property 
			to true -->
  <property name="exposeSpringMacroHelpers" value="true"/>
   
	</bean>



<prop key="defaultEncoding">UTF-8</prop>
<property name="contentType" value="text/html" />

这两部分为处理乱码的关键。
文件编码不支持中文等原因也可能产生乱码,需调整至一致。




你可能感兴趣的:(spring,mvc,freemarker,delay,macros)