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
那么,如何“复位”时间变量或设置一个“空”的价值,以及如何检查为空(但不是空)时间值?