我正在尝试计算" - " s的地图和打印行中的值的总和(此行的长度应为sum-1)。 这是我的功能代码:
<#function getSeparatorLine map>
<#if !map?has_content>
<#return "">
</#if>
<#local borderLength = 0>
<#list map?keys as item>
<#local borderLength = borderLength + item + 1>
</#list>
<#return ""?right_pad(borderLength - 1, "-")>
</#function>
我收到了一条freemarker错误说:
ERROR freemarker.runtime - Error executing FreeMarker template
freemarker.core.NonNumericalException: For "-" left-hand operand: Expected a number, but this has evaluated to a string (wrapper: f.t.SimpleScalar):
==> borderLength [in template "negative_events_report.template" at line 38, column 27]
有什么建议吗?
答案 0 :(得分:0)
item
是一个字符串,因此borderLength + item + 1
实际上是字符串连接而不是算术加法。假设map
包含数值,则应编写map?values
,而不是map?keys
。