spring配置freemarker
Posted 那家那人那小伙
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了spring配置freemarker相关的知识,希望对你有一定的参考价值。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<!-- FreeMarker视图解析 如返回student。。在这里配置后缀名htm和视图解析器。。 -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.freemarker.FreeMarkerView" />
<property name="suffix" value=".html" />
<property name="contentType" value="text/html;charset=UTF-8" />
<property name="exposeRequestAttributes" value="true" />
<!-- 不开启session -->
<property name="exposeSessionAttributes" value="false" />
<property name="requestContextAttribute" value="request"/>
<!-- 使用Spring提供的FreeMarker宏 -->
<property name="exposeSpringMacroHelpers" value="true" />
</bean>
<!-- freemarker的配置 -->
<bean id="freemarkerConfigurer"
class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
<property name="templateLoaderPath" value="/WEB-INF/inborn" />
<property name="defaultEncoding" value="UTF-8" />
<property name="freemarkerSettings">
<props>
<!-- 用来指定更新模版文件的间隔时间,相当于多长时间检测一下是否有必要重新加载模版文件, 0 表示每次都重新加载,否则为多少毫秒钟检测一下模版是否更改
2147483647 -->
<prop key="template_update_delay">0</prop>
<prop key="locale">zh_CN</prop>
<prop key="defaultEncoding">UTF-8</prop>
<prop key="url_escaping_charset">UTF-8</prop>
<prop key="datetime_format">yyyy-MM-dd HH:mm:ss</prop>
<prop key="date_format">yyyy-MM-dd</prop>
<prop key="number_format">#.##</prop>
<prop key="whitespace_stripping">true</prop>
<!--空值处理 -->
<prop key="classic_compatible">true</prop>
<prop key="boolean_format">true,false</prop>
</props>
</property>
<property name="freemarkerVariables">
<map>
<entry key="moneyShow" value-ref="moneyFre"/>
<entry key="moneyGroup" value-ref="moneyFormat"/>
<entry key="friendlyLength" value-ref="lengthFre"/>
<entry key="timeFormat" value-ref="timeFre"/>
<entry key="title" value="胤宝"/>
<entry key="monyType" value="¥"/>
</map>
</property>
</bean>
<!-- 自定义金额标签 -->
<!-- 自定义金额标签 -->
<bean id="moneyFre" class="com.inborn.inshop.freemarker.MoneyFre"></bean>
<bean id="moneyFormat" class="com.inborn.inshop.freemarker.MoneyFormat"></bean>
<bean id="lengthFre" class="com.inborn.inshop.freemarker.LengthFre"></bean>
<bean id="timeFre" class="com.inborn.inshop.freemarker.TimeFre"></bean>
</beans>
以上是关于spring配置freemarker的主要内容,如果未能解决你的问题,请参考以下文章