Handling null values in Freemarker

前端 未结 5 2084
时光说笑
时光说笑 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:55

    Use ?? operator at the end of your <#if> statement.

    This example demonstrates how to handle null values for two lists in a Freemaker template.

    List of cars:
    <#if cars??>
        <#list cars as car>${car.owner};
    
    List of motocycles:
    <#if motocycles??>
        <#list motocycles as motocycle>${motocycle.owner};
    
    

提交回复
热议问题