首页 > 解决方案 > 使用 put on a map in velocity 打印指令

问题描述

我在动态修改的速度模板中有一张地图。下面是一个简化的例子来说明这一点。

#set($testMap = {})

## this stuff isn't static so I can't just create 
## the map as key-value pairs in the declaration

$testMap.put("a", "A")
$testMap.put("b", "B")

$testMap

以上生成

$testMap.put("a", "A") $testMap.put("b", "B") {a=A, b=B}

我不希望“放置”指令显示在模板中。

标签: velocity

解决方案


我建议您使用条目初始化地图:

#set (testMap = {"a" :  "A" , "b" : "B"})

推荐阅读