FreeMarker - 如何使用名称中带有连字符的元素

FreeMarker - How to use elements that have hypehns in the name

我如何使用 Freemarker 模板中包含连字符的非顶级元素的元素

${variable.vars[“元素名称”]}

似乎不​​起作用。这给了我一个错误

"Expected a string or something automatically convertible to string (number, date or boolean), but this evaluated to a sequence+hash"

当我尝试将其转义为 ${variable.element\-name}

Exception in thread "main" org.milyn.cdr.SmooksConfigurationException: Error invoking @Initialize method 'initialize' on class 'org.milyn.templating.freemarker.FreeMarkerTemplateProcessor'.
at org.milyn.cdr.annotation.Configurator.invoke(Configurator.java:457)

不使用 \- 功能的 variable.element\-name 相当于 variable['element-name']。 (通常,在 FreeMarker 中 foo.barfoo['bar'] 相同。)

但是,\-报错真的很奇怪。也许你在那里有一个非常古老的 FreeMarker 依赖? (尝试 ${.version} 打印的内容。)此外,该堆栈跟踪中是否没有原因异常?查看根 FreeMarker 错误消息可能会有所帮助。