Handling null values in Freemarker

前端 未结 5 2093
时光说笑
时光说笑 2020-12-07 22:19

How to handle null values in Freemarker? I get some exceptions in the template when null values are present in data.

5条回答
  •  没有蜡笔的小新
    2020-12-07 22:54

    You can use the ?? test operator:

    This checks if the attribute of the object is not null:

    <#if object.attribute??>
    

    This checks if object or attribute is not null:

    <#if (object.attribute)??>
    

    Source: FreeMarker Manual

提交回复
热议问题