判断FreeMarker是否为空

 

转自:https://blog.csdn.net/lwt976647637/article/details/73135933

1)判断Map数据是否为空

1<#ifmaster??&&(master?size>0)>
2 
3    <#list master?keys askey>
4 
5     <span>${key}:${master[key]!}</span>
6 
7    </#list>
8 
9</#if>

 

2)判断List数据是否为空

1 <#if tables?exists>
2 
3   <#listtables as table>
4 
5     ${table}
6 
7   </#list>
8 
9 </#if>

3)解决为空的问题:

A加个感叹号可以解决为空的问题

1 ${(emp.group)!}

B加上括号,感叹号解决对象导航为空的问题

1 ${(emp.group.name)!"group为空或者name为空"} 

C感叹号还可以解决未定义为空的问题-->

 1  ${(a.b)!("a.b未定义")}  
 2 
 3   <#--(a.b)??判断a.b是否为空-->
 4 
 5     <#if (a.b)??>
 6 
 7        不为空
 8 
 9       <#else>
10 
11        为空
12 
13     </#if>
14 
15   <br/>
16 
17 ${(a.b)???string}

猜你喜欢

转载自www.cnblogs.com/thyHome/p/9222476.html