我从 apache ofbiz 开发书中获得了以下代码:
<#macro displayData data>
<#if data?is_sequence>
<#assign keys = data?first?keys/>
<#else>
<#assign keys = data?keys/>
</#if>
<#-- Header -->
<tr>
<#list keys as key>
<td class="dark-grid"><b>${key}</b></td>
</#list>
</tr>
<#-- Data -->
<#if data?is_sequence>
<#list data as record>
<tr>
<#list keys as key>
<td class="light-grid">${record[key]!""}</td>
</#list>
</tr>
</#list>
<#else>
<tr>
<#list keys as key>
<td class="light-grid">${data[key]!""}</td>
</#list>
 <h1>Processed script: "${parameters.scriptName}"</h1>
<#if data?has_content && (data?is_sequence || data?is_hash)>
</tr> </#if>
</#if>
</#macro>
当我尝试在前端显示某些内容时,出现以下错误:
Error on line 31, column 38 in component://crmsfa/webapp/crmsfa/tests/displayData.ftl Expecting a string, date or number here, Expression record[key]!"" is instead a freemarker.ext.beans.SimpleMethodModel The problematic instruction: ---------- ==> ${record[key]!""} [on line 31, column 36 in component://crmsfa/webapp/crmsfa/tests/displayData.ftl] in user-directive displayData [on line 7, column 9 in component://crmsfa/webapp/crmsfa/tests/displayData.ftl] ---------- Java backtrace for programmers: ---------- freemarker.core.NonStringException: Error on line 31, column 38 in component://crmsfa/webapp/crmsfa/tests/displayData.ftl Expecting a string, date or number here, Expression record[key]!"" is instead a freemarker.ext.beans.SimpleMethodModel at freemarker.core.Expression.getStringValue(Expression.java:126) at
freemarker.core.Expression.getStringValue(Expression.java:93)
我想知道两件事,以便我可以首先调试这个我从来没有遇到过${record[ key ]!""}(变量中的 !"" )或data?first?keys/>有人可以解释一下这两个表达式的语义。