問題:在ftl頁面截取字符串
${row?substring(23,44)}
問題:在頁面進行if語句的判斷
<#if attachmentUrlList??>
<#list attachmentUrlList as row>
<a class="attachment_download" id="attachmentId" href="${base + row}" data-evt="trash" data-toggle="tooltip" title="附件下載"><i class="icon icon-note"></i>下載${row?substring(23,44)}</a>
</#list>
</#if>
事實證明:上面的紅色代碼是有問題的,判斷list是否為空,應該用exist
<#if attachmentUrlList?exists>
<#list attachmentUrlList as row>
<a class="attachment_download" id="attachmentId" href="${base + row}" data-evt="trash" data-toggle="tooltip" title="附件下載"><i class="icon icon-note"></i>下載</a>
</#list>
<#else>
</#if>
(1)判斷Map數據是否為空
<#ifmaster??&&(master?size>0)>
<#list master?keys askey>
<span>${key}:${master[key]!}</span>
</#list>
</#if>
(2)判斷List數據是否為空
<#if tables?exists>
<#listtables as table>
${table}
</#list>
</#if>
(3)解決為空的問題:
A:加個感嘆號可以解決為空的問題
${(emp.group)!}
B:加上括號,感嘆號解決對象導航為空的問題
${(emp.group.name)!"group為空或者name為空"}
C:感嘆號還可以解決未定義為空的問題-->
${(a.b)!("a.b未定義")}
<#--(a.b)??判斷a.b是否為空-->
<#if (a.b)??>
不為空
<#else>
為空
</#if>
<br/>
${(a.b)???string}