我在Freemarker的創建功能:與參數Freemarker的功能,可以爲空
<#function formatDate anyDate> <#assign dateFormat = read_from_configuration() /> <#if anyDate??> <#return anyDate?date(dateFormat) /> <#else > <#return '' /> </#if> </#function>
我這樣稱呼它:${formatDate(object.someDate)}
。
這一切工作,直到someDate
爲空。在這種情況下,我得到異常:
Error executing macro: formatDate required parameter: anyDate is not specified.
我怎樣才能做到這一點?如果參數值爲null,我希望函數能夠工作。
事情是,當參數爲空時,它甚至不在函數內部。它只是在調用該函數時拋出異常。這些檢查不會被調用。 – 2011-01-14 08:22:36