Liferay 如何分配Null或“空”;“空的”;Freemarker时间变量的值?

Liferay 如何分配Null或“空”;“空的”;Freemarker时间变量的值?,liferay,freemarker,Liferay,Freemarker,我正在使用Freemarker构建Liferay应用程序显示模板。该模板使用循环在一组实体(期刊文章)上进行迭代。该模板使用数个日期和时间类型的变量。如何重置这些变量或在循环的每次迭代中检查“空” 假设我们在循环中有这个代码,在循环的某些迭代中,“starthour”可能是空的: <#assign xPathSelector = saxReaderUtil.createXPath("dynamic-element[@name='start_hour']") /> <#assig

我正在使用Freemarker构建Liferay应用程序显示模板。该模板使用循环在一组实体(期刊文章)上进行迭代。该模板使用数个日期和时间类型的变量。如何重置这些变量或在循环的每次迭代中检查“空”

假设我们在循环中有这个代码,在循环的某些迭代中,“starthour”可能是空的:

<#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>
那么,如何“重置”时间变量或为其设置“空”值,以及如何检查空(但不是空)时间值?

您不能取消设置值(如果可以,读取它将返回到更高的范围,如果该变量出现在数据模型中,可能会导致错误)。因此,要么必须引入一个布尔
startTimeSet
变量,要么必须选择一个特殊的空值。由于时间值没有“自然”空值,您可以只使用
,然后在对其进行任何操作之前,使用
?has\u content
检查该值

<#if (starttime >0) >
<#if starttime.has_content>
<#if starttime!="">
<#if starttime??>
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