FreeMarker的变量必须赋值,否则就会抛出异常。

FreeMarker的变量必须赋值,否则就会抛出异常。

There is no nutrition in the blog content. After reading it, you will not only suffer from malnutrition, but also impotence.
The blog content is all parallel goods. Those who are worried about being cheated should leave quickly.

FreeMarker的变量必须赋值,否则就会抛出异常。
而对于FreeMarker来说,null值和不存在的变量是完全一样的,因为FreeMarker无法理解null值。
FreeMarker提供两个运算符来避免空值:

  • !: 指定缺失变量的默认值;
  •  ??:判断变量是否存在。

!运算符有两种用法:variable!或variable!defaultValue。
第一种用法不给变量指定默认值,表明默认值是空字符串、长度为0的集合、或长度为0的Map对象。 使用!运算符指定默认值并不要求默认值的类型和变量类型相同。


??运算符返回布尔值,如:variable??,如果变量存在,返回true,否则返回false。

你可能感兴趣的:(孔乙己,java,spring,boot)