0
我正在使用Freemarker構建Liferay應用程序顯示模板。模板使用循環遍歷實體集(期刊文章)。該模板使用多個類型日期和時間的變量。如何重置這些變量或在循環的每次迭代中檢查「空」?如何將空值或「空」值分配給Freemarker時間變量?
比方說,我們有內循環這個代碼,它可能是「starthour」在此循環中的一些Interations是空的:
<#assign xPathSelector = saxReaderUtil.createXPath("dynamic-element[@name='start_hour']") />
<#assign starthour = xPathSelector.selectSingleNode(rootElement).getStringValue()?trim />
<#assign xPathSelector = saxReaderUtil.createXPath("dynamic-element[@name='start_minutes']") />
<#assign startminutes = xPathSelector.selectSingleNode(rootElement).getStringValue()?trim />
<#if starthour!="">
<#assign startTimeString= starthour +":"+startminutes>
<#assign starttime = startTimeString?time["HH:mm"]>
<#else>
<#assign starttime = 0>
</#if>
在這個例子中,我開始時間設置爲0,但當starthour爲空時,我也嘗試將它設置爲空字符串。
我已經嘗試過這些方法來檢查「空」變量:
<#if (starttime >0) >
<#if starttime.has_content>
<#if starttime!="">
我無法檢查
<#if starttime??>
後可變曾經被我設置循環。無論我嘗試,我總是得到錯誤像這樣的,當我用我的腳本中的Liferay:
The only legal comparisons are between two numbers, two strings, or two dates.
Left hand operand is a freemarker.template.SimpleDate
Right hand operand is a freemarker.template.SimpleNumber
那麼,如何「復位」時間變量或設置一個「空」的價值,以及如何檢查爲空(但不是空)時間值?