0
我從Apache ofbiz的發展簿下面的代碼:在freemarker的變量表達式中「!」是什麼意思?
<#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]!「」}(變量內部的「!」)或< #assign keys = data?first?keys />有人可以解釋這兩個表達式的語義含義。
感謝。我已經想通了,但忘了回答。 –
只是爲了澄清,對自己的工作做了數據[關鍵]? –