本文介绍了在Freemarker中处理空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Freemarker中处理null值?当数据中存在null值时,模板中会出现一些异常.
How to handle null values in Freemarker? I get some exceptions in the template when null values are present in data.
推荐答案您可以使用??测试运算符:
You can use the ?? test operator:
这将检查对象的属性是否不为空:
This checks if the attribute of the object is not null:
<#if object.attribute??></#if>这将检查对象或属性是否不为空:
This checks if object or attribute is not null:
<#if (object.attribute)??></#if>来源:FreeMarker手册
更多推荐
在Freemarker中处理空值
发布评论