问题描述
将空值放入速度上下文或根本不放入变量是否有区别。
VeLocityContext ctx = new VeLocityContext();
ctx.put("v",null);
或
VeLocityContext ctx = new VeLocityContext();
-- no put
看起来没有,因为速度不会检查是否存在。
相反,它从地图中获取变量并在两种情况下都获得 null
。
解决方法
您可以将上下文放入自身:
ctx.put("ctx",ctx);
然后在 VTL 中:
#if($ctx.containsKey('v'))
...
#else
...
#end