zoukankan      html  css  js  c++  java
  • 两种Freemarker模板路径设置方法

    <beans>
    <bean id="freeMarkerConfigurer" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
    <property name="templateLoaderPath" value="/WEB-INF/config/template/" />
    <property name="freemarkerSettings">
    <props>
    <prop key="template_update_delay">0</prop>
    <prop key="default_encoding">GBK</prop>
    <prop key="locale">zh_CN</prop>
    </props>
    </property>
    </bean>
    <bean id="freeMarkerConfiguration" class="org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean">
    <property name="templateLoaderPath" value="file:D:/Java/workspace/project/WebContent/WEB_INF/config/template" />
    </bean>
    <bean id="templateService" class="com.ahtec.ssi.service.impl.TemplateServiceFreeMarkerImpl">
    <property name="freeMarkerConfigurer" ref="freeMarkerConfigurer" />
    <property name="freeMarkerConfiguration" ref="freeMarkerConfiguration" />
    </bean>
    </beans>
    //WEB
    Template t = freeMarkerConfigurer.getConfiguration().getTemplate(templateName);
    return FreeMarkerTemplateUtils.processTemplateIntoString(t, model);
    //NONE WEB
    Template t = freeMarkerConfiguration.getTemplate(templateName);
    return FreeMarkerTemplateUtils.processTemplateIntoString(t, model);

    在 web 中,可以方便地定位到WEB_INF目录,但在非web中就不那么容易了。综合考虑,将ftl模板放在classpath目录挺好的。用classpath:来定位模板位置。

    补一段代码:

    Freemarker多路径配置方法:

    <bean id="freemarkerConfig"
    class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
    <property name="templateLoaderPaths">
    <list>
    <value>/Freemarker/</value>
    <value>/Freemarker/error/</value>
    </list>
    </property>
    </bean>

     

     

  • 相关阅读:
    Python基础-字符串方法 、文件操作
    Python基础-列表、字典
    Python基础作业-用户登录
    LeetCode 78. Subsets
    LeetCode 77. Combinations
    LeetCode 76. Minimum Window Substring
    LeetCode 74. Search a 2D Matrix
    LeetCode 73. Set Matrix Zeroes
    LightOJ 1043
    LightOJ 1042
  • 原文地址:https://www.cnblogs.com/ibook360/p/2548303.html
Copyright © 2011-2022 走看看