速度模板语言:如何导入EscapeTool [英] Velocity Template Language: How to import EscapeTool

查看:114
本文介绍了速度模板语言:如何导入EscapeTool的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to use unurl for my mapping template.

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

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

I wrote the following mapping template, but $esc.unurl([...]) doesn't work. I couldn't figure out how to fix it. One reason might be that I am missing an import, but I don't know how to import the EscapeTool properly.

#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
}

推荐答案

您需要将其添加到

tools.xml配置示例(如果要与VelocityView一起使用):

Example tools.xml config (if you want to use this with VelocityView):

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

或使用代码在速度上下文中添加:

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

这篇关于速度模板语言:如何导入EscapeTool的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆