FreeMarker 对null值的处理
以下引用官方描述:
The FreeMarker template language doesn't know the Java language null at all. It doesn't have null keyword, and it can't test if something is null or not.
1.判断是否存在,通过exists关键字或者"??"运算符。都将返回一个布尔值
user.name?exists user.name?? Html代码 收藏代码 <#if user.name?exists> //TO DO </#if> <#if user.age??> //TO DO </#if>
2.忽略null值
假设前提:user.name为null ${user.name},异常 ${user.name!},显示空白 ${user.name!'vakin'},若user.name不为空则显示本身的值,否则显示vakin ${user.name?default('vakin')},同上 ${user.name???string(user.name,'vakin')},同上
eg:当outCar.startNumberKm为空时则取startNumberKmByLast作用域中的值
<div class="grid_5 lable-right"> <label class="form-lbl">起始公里数(km):</label> </div> <div class="grid_6"> <input type="text" name="startNumberKm" id="startNumberKm" maxlength="10" value="${outCar.startNumberKm!'${startNumberKmByLast}'}" class="form-txt" /> </div> <div class="grid_1"><em class="form-req">*</em></div>
相关推荐
81314797 2020-11-18
89314493 2020-11-03
81941231 2020-09-17
thisisid 2020-09-09
如狼 2020-08-15
82384399 2020-06-16
86384798 2020-05-12
80183053 2020-05-02
86384798 2020-04-26
86384798 2020-04-11
rionchen 2020-04-09
86384798 2020-04-07
86384798 2020-04-04
80183053 2020-03-07
87201943 2020-03-06
83961233 2020-02-26
87201943 2020-02-21