2016-03-31 57 views
0

您好我有一定的要求,以创建不同的实体FTL,如何使用弹簧org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean

我想加载从嵌套的文件夹FTL的,好像,我加载Freemarker模板嵌套的文件夹realted ftl的应该是一个文件夹,然后所有的宏都活到Macro文件夹中。

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

此调试弹簧类

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

相反的阵列后,不working.Using弹簧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> 

此外,templateLoaderPath行为类似于单个字符串。

回答

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> 
+0

感谢ddekany,它的工作, –

+0

(然后将其标记为答案。) – ddekany