首页 > Web开发 > 详细

Mingyang.net:自定义FreeMarkerView

时间:2014-08-08 17:56:16      阅读:468      评论:0      收藏:0      [点我收藏+]

自定义FreeMarkerView的目的是为了放一些公共的变量到FreeMarker模版里面.
spring-context.xml:

<!-- ********************************************************************** 
     ** FreeMaker解析器                                                      ** 
     ********************************************************************** -->
<bean class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
    <!--<property name="viewClass" value="org.springframework.web.servlet.view.freemarker.FreeMarkerView" />-->
    <property name="viewClass" value="net.mingyang.cms.util.FtlView" />   
    <property name="contentType" value="text/html;charset=UTF-8" />
    <property name="exposeRequestAttributes" value="true" />  
    <property name="exposeSessionAttributes" value="true" />  
    <property name="exposeSpringMacroHelpers" value="true" />
    <!-- <property name="suffix" value=".ftl" /> -->  
    <property name="order" value="0" />
</bean>
<bean class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer"> 
    <property name="templateLoaderPath" value="/WEB-INF/views/" /> 
    <property name="freemarkerSettings"> 
        <props> 
            <prop key="template_update_delay">0</prop> 
            <prop key="default_encoding">UTF-8</prop> 
            <prop key="number_format">0.##########</prop> 
            <prop key="datetime_format">yyyy-MM-dd HH:mm:ss</prop>
            <prop key="date_format">yyyy-MM-dd</prop> 
            <prop key="classic_compatible">true</prop> 
            <prop key="template_exception_handler">ignore</prop> 
        </props> 
    </property> 
</bean>

FtlView.java:

package net.mingyang.cms.util;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.servlet.view.freemarker.FreeMarkerView;

public class FtlView extends FreeMarkerView
{
    @Override
    protected void exposeHelpers(Map<String, Object> model,
            HttpServletRequest request) throws Exception
    {
        model.put("contextPath", request.getContextPath());
        super.exposeHelpers(model, request);
    }
    
}

Mingyang.net:自定义FreeMarkerView,布布扣,bubuko.com

Mingyang.net:自定义FreeMarkerView

原文:http://www.cnblogs.com/eastson/p/3899617.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!