【问题标题】:How can i load nested folders for FreeMarker template using spring org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean如何使用 spring org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean 为 FreeMarker 模板加载嵌套文件夹
【发布时间】:2016-07-19 17:46:57
【问题描述】:

您好,我需要为不同的实体创建 ftl,

我想从嵌套文件夹中加载 ftl,就像所有 A realted ftl 都应该在 A 文件夹中,然后所有的 Macro 都在 Macro 文件夹中。

<bean id="freeMarkerConfigurationFactory" class="org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean">
    <property name="templateLoaderPath" value="classpath:freemarker/Account/"/>
    <property name="preferFileSystemAccess" value="false"/>
</bean>

这不起作用。使用 spring 4

<bean id="freeMarkerConfigurationFactory" class="org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean">
    <property name="templateLoaderPath"> 
        <value> "classpath:freemarker/Account/" , "classpath:freemarker/Macro/"</value>
    </property>
    <property name="preferFileSystemAccess" value="false"/>
</bean>

也是调试完spring类之后

public void setTemplateLoaderPath(String templateLoaderPath) {
    this.templateLoaderPaths = new String[] {templateLoaderPath};
}

templateLoaderPath 的行为类似于单个字符串,而不是数组。

【问题讨论】:

    标签: spring freemarker


    【解决方案1】:

    您需要设置templateLoaderPaths 属性(注意末尾的s),而不是templateLoaderPath

    我相信 Spring 的语法会是(还没有测试过...):

    <property name="templateLoaderPaths"
              values="classpath:freemarker/Account/,classpath:freemarker/Macro/"
    />
    

    或更长的形式:

    <property name="templateLoaderPaths">
      <array>
        <value>classpath:freemarker/Account/</value>
        <value>classpath:freemarker/Macro/</value>
      </array>
    </property>
    

    【讨论】:

    • (然后将其标记为答案。)
    猜你喜欢
    • 2012-06-04
    • 2013-01-23
    • 1970-01-01
    • 1970-01-01
    • 2011-05-11
    • 2013-10-21
    • 1970-01-01
    • 1970-01-01
    • 2013-03-18
    相关资源
    最近更新 更多