springmvc+freemarker实现html视图备忘

首先,在pom里添加如下依赖
		
		
		<dependency>
			<groupId>org.springframeworkgroupId>
			<artifactId>spring-context-supportartifactId>
			<version>5.0.5.RELEASEversion>
		dependency>
		<dependency>
			<groupId>org.freemarkergroupId>
			<artifactId>freemarkerartifactId>
			<version>2.3.28version>
		dependency>
在spring的xml配置中添加如下配置

<bean id="freeMarkerViewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
	
	<property name="contentType" value="text/html;charset=UTF-8" />
	
	<property name="suffix" value=".html" />
bean>

<bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
	
	<property name="defaultEncoding" value="UTF-8" />
	<property name="freemarkerSettings">
		<props>
			
			<prop key="number_format">#prop>
		props>
	property>
	
	<property name="freemarkerVariables">
		<map>
			<entry key="xml_escape">
				<bean class="freemarker.template.utility.XmlEscape" />
			entry>
		map>
	property>
	
	<property name="templateLoaderPaths">
		<list>
			<value>/WEB-INF/freemarker/value>
			
			
		list>
	property>
bean>
不要用mvc:resolvers/这种配置方法,配置项不全,中文乱码,截止目前5.1.2版本的spring尚无法解决,只能用上面bean的配置方法。

—原创不易,转帖请注明出处,shizhongqi


你可能感兴趣的:(springmvc+freemarker实现html视图备忘)