【问题标题】:FreeMarker inline template (load from database) in Smooks not interpretedSmooks 中的 FreeMarker 内联模板(从数据库加载)未解释
【发布时间】:2012-07-17 19:07:02
【问题描述】:

全部,

我尝试从 Smooks 配置文件中的数据库加载 FreeMarker 模板,并使用内置 INTERPRET 将字符串解析为模板。但是,输出正是我存储在数据库中的模板。

以下是 Smooks 配置文件的一部分:


....

<resource-config selector="hs:TravelerProfile">
    <resource>org.milyn.delivery.DomModelCreator</resource>
</resource-config>
<db:executor executeOnElement="hs:TravelerProfile" datasource="StagingDS">
          <db:statement>select freeMarker_template from template_lookup where agencyid='111'; 
          </db:statement>
          <db:resultSet name="mytemplate" />
    </db:executor>

<ftl:freemarker applyOnElementNS="www.travel.com" applyOnElement="TravelerProfile">

    <ftl:template>
    < !--       
    <#assign templateSource = r"${mytemplate[0].freeMarker_template}">
    <#assign inlineTemplate = [templateSource, "myInlineTemplate"]?interpret>
    <@inlineTemplate/> 
    -- >
    </ftl:template>
</ftl:freemarker>

.....


我存储在数据库中的模板如下:

<#ftl ns_prefixes={"D":"www.hhs.gov/travel"}>
<?xml version="1.0" encoding="UTF-8"?>
<po:PoHeadersInterfaceCollection xmlns:po="https://www.travel.com/xmlns/financial/po112007.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://www.travel.com/xmlns/financial/po112007.xsd">
  <po:PoHeadersInterface>
    <po:interfaceSourceCode>VendorName</po:interfaceSourceCode>
    <po:poLinesInterfaceCollection>
      <po:PoLinesInterface>
        <po:PoDistributionsInterfaceCollection>
          <po:PoDistributionsInterface>
            <po:destinationOrganizationId>${TravelerProfile.TravelerOfficeCode}
            </po:destinationOrganizationId>
          </po:PoDistributionsInterface>
        </po:PoDistributionsInterfaceCollection>
      </po:PoLinesInterface>
    </po:poLinesInterfaceCollection>
  </po:PoHeadersInterface>
</po:PoHeadersInterfaceCollection>

======================================

由于某种原因,输出正是上面的模板本身。 "${TravelerProfile.TravelerOfficeCode}" 尚未评估!请帮忙!!!

谢谢!!!

艾格尼丝

【问题讨论】:

    标签: inline freemarker template-engine smooks


    【解决方案1】:

    Sine mytemplate[0].freeMarker_template 返回模板源代码本身(或者至少我假设是这样),并且由于您使用的是原始字符串文字 (r"..."),因此您的模板的源代码实际上是 ${mytemplate[0].freeMarker_template},然后由?interpret 评估为模板源代码。更正后的模板是:

    <#assign inlineTemplate = [mytemplate[0].freeMarker_template, "myInlineTemplate"]?interpret>
    <@inlineTemplate/>
    

    也可以写成:

    <@([mytemplate[0].freeMarker_template, "myInlineTemplate"]?interpret) />
    

    或者如果您不需要 "myInlineTemplate" 模板名称:

    <@mytemplate[0].freeMarker_template?interpret />
    

    【讨论】:

      猜你喜欢
      • 2013-12-19
      • 2010-09-26
      • 2013-03-18
      • 2011-05-11
      • 1970-01-01
      • 2019-10-28
      • 1970-01-01
      • 1970-01-01
      • 2011-04-11
      相关资源
      最近更新 更多