【问题标题】:Velocity Template Language: How to import EscapeToolVelocity 模板语言:如何导入 EscapeTool
【发布时间】:2019-12-22 14:16:36
【问题描述】:

我正在尝试将unurl 用于我的映射模板。

  $url                         -> hello here & there
  $esc.url($url)               -> hello+here+%26+there
  $esc.unurl($esc.url($url))   -> hello here & there

我编写了以下映射模板,但 $esc.unurl([...]) 不起作用。我不知道如何解决它。一个原因可能是我缺少导入,但我不知道如何正确导入 EscapeTool。

#set($httpPost = $input.path('$').split("&"))
{
#foreach( $kvPair in $httpPost )
 #set($kvTokenised = $kvPair.split("="))
 #if( $kvTokenised.size() > 1 )
   "$kvTokenised[0]" : "$esc.unurl($kvTokenised[1])"#if( $foreach.hasNext ),#end
 #else
   "$kvTokenised[0]" : ""#if( $foreach.hasNext ),#end
 #end
#end
}

【问题讨论】:

  • 我没有设法安装该工具,所以我最终通过 Python 找到了不同的解决方案。

标签: aws-api-gateway velocity apache-velocity


【解决方案1】:

你需要添加到tools.xml

示例 tools.xml 配置(如果您想将其与 VelocityView 一起使用):

<tools>
  <toolbox scope="application">
    <tool class="org.apache.velocity.tools.generic.EscapeTool"/>
  </toolbox>
</tools>

或者使用code将其添加到速度上下文中:

ModelMap model = new ModelMap();
model.put("esc", new EscapeTool());
VelocityEngineUtils.mergeTemplateIntoString(
            velocityEngine, "template.vm", "UTF-8", model)

【讨论】:

    猜你喜欢
    • 2023-03-10
    • 2019-08-03
    • 1970-01-01
    • 2022-12-06
    • 2022-09-27
    • 2018-01-29
    • 2019-08-18
    • 2011-09-01
    • 1970-01-01
    相关资源
    最近更新 更多