zoukankan      html  css  js  c++  java
  • SpringMVC中Freemarker获取项目根目录

    https://blog.csdn.net/whatlookingfor/article/details/51538995

    在SpringMVC框架中使用Freemarker试图时,要获取根路径的方式如下:

    <!-- FreeMarker视图解析 如返回userinfo。。在这里配置后缀名ftl和视图解析器。。 -->
    <bean id="viewResolverFtl"
        class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
        <property name="viewClass"
            value="org.springframework.web.servlet.view.freemarker.FreeMarkerView" />
        <property name="suffix" value=".ftl" />
        <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="requestContextAttribute" value="request" />
        <property name="cache" value="true" />
        <property name="order" value="0" />
    </bean>

    其中property name=”requestContextAttribute” value=”request”是关键。 
    意思是把Spring的RequestContext对象暴露为变量request 
    利用${request.contextPath}来获取应用程序的contextPath

    如果是集成了Springboot,在配置文件中,只需要设置 
    spring.freemarker.request-context-attribute=request 即可

    ftl中的页面设置如下:

    根路径配置:
    spring.freemarker.request-context-attribute=request
    #freemarker 配置
    spring.freemarker.expose-request-attributes=true
    spring.freemarker.expose-session-attributes=true
    spring.freemarker.expose-spring-macro-helpers=true
    spring.freemarker.request-context-attribute=request
    spring.freemarker.charset=utf-8
    spring.freemarker.cache=false
    spring.freemarker.content-type=text/html
    spring.freemarker.suffix= .ftl
    spring.freemarker.template-loader-path=classpath:/templates/
    
    #应用名称
    server.servlet.context-path=/

     其中property name=”requestContextAttribute” value=”request”是关键。 
    意思是把Spring的RequestContext对象暴露为变量request 
    利用${request.contextPath}来获取应用程序的contextPath

  • 相关阅读:
    iOS之UITableView的上拉刷新
    iOS xml文件的解析方式 XMLDictionary,GDataXMLNode,NSXMLParser
    iOS学习基本常识
    iOS常用宏定义
    iOS查错机制
    轻量级sqlite是增删改查
    iOS开发UI篇—ios应用数据存储方式(归档) :转发
    iOS面向对象的建模:MVC(OC基础)
    iOS下bound,center和frame
    CSS----学习2
  • 原文地址:https://www.cnblogs.com/newlangwen/p/9269755.html
Copyright © 2011-2022 走看看