freemark 使用笔记

1、空值处理运算符

FreeMarker的变量必须赋值,否则就会抛出异常。而对于FreeMarker来说,null值和不存在的变量是完全一样的。FreeMarker提供两个运算符来避免空值:
1. !:指定缺失变量的默认值;

2. ??:判断变量是否存在。

这两个符号的用法看下面的例子

2、判断字符串是否为空

<#if item.icon?? && item.icon !="">
   <i class=item.icon></i>
 </#if>

3、在页面里面用!避免变量没有赋值的错误

<input type="text" class="form-control" placeholder="上级组织" data-rule-maxlength="20" autocomplete="off" value="${(orgName)!''}" >

时间类型的变量

<input type="text" class="form-control"  value='${(org.invalidTime?string("yyyy-MM-dd "))!""}' />

猜你喜欢

转载自blog.csdn.net/liyongjian12/article/details/79398288