FreeMarker中的< if>标签

本文介绍了FreeMarker模板引擎中&lt;if&gt;标签的使用方法,包括如何判断对象是否存在及字符串或数字的比较,并提供了具体的语法示例。

FreeMarker中的< if>标签除了里面直接判断 boolean 类型的变量外,也可以进行表达式判断,有几个细节记录一下

1. 判断对象是否存在(null)

经常会用到,如果对象 != null 则xxxx,在freemarker中表达比较奇怪,例如判断 target 是否为null,如果不为 nll 则做xxx动作

< if target>

    xxxx

</ if>

(目标变量后面连续两个??)

2. 字符串或数字比较

java里标准字符串比较需要 .equals() 方法,在freemarkder中进行了简化,字符串的比较方法和数字做到完全一样

< if str ="= "success"" >

    xxx

</ if>

< if str ="= "error"" >

    xxx

</ if>


转载于:https://my.oschina.net/guoenzhou/blog/270163

分析代码:<#setting datetime_format="yyyy-MM-dd"/> <#import "/decorators/includes/macros.ftl" as m> <#assign ww = JspTaglibs["/WEB-INF/webwork.tld"] /> <div id="breadcrumbs"> <a href="${req.contextPath}/index.action">Home</a> > To Do </div> <div class="app"> <#list toDoItemsMap?keys as owner> <#assign toDoItems = toDoItemsMap[owner]?if_exists> <#if ercService.CanSignoffRuncardMemberByE1Manager(userLogin.employeeInfo.employeeNo)?has_content> <#if specialDuty?default("") ==""> <a href="toDo.action?specialDuty=T">Todo List for E1 specialDuty</a> <#else> <a href="toDo.action">Normal Todo List</a> </#if> </#if> <h3><@m.directoryLink owner/>'s ToDo List</h3> <table border="0" cellspacing="2" cellpadding="3" width="100%" id="todo"> <thead> <tr> <th>Case No</th> <th>Lot Id</th> <th>Applicant</th> <th>Product Id</th> <th>Stage Id</th> <th>Status</th> <th>Purpose</th> <th>Submit Date</th> </tr> </thead> <tbody> <#list toDoItems?sort_by('caseNo') as todo> <#if specialDuty?default("") =="" || todo.queuedOwners?seq_contains(todo.e1OrgId)> <tr class="b"> <td><a href="viewWorkFlowEntry.action?requestFormId=${todo.id}&specialDuty=${specialDuty?default("")}">${todo.caseNo?default("Not Assigned")?if_exists}</a></td> <td>${todo.lotId?if_exists}</td> <td><@m.directoryLink todo.applicant?if_exists/></td> <td>${todo.prodId?if_exists}</td> <td>${todo.lotStageId?if_exists}</td> <td>${todo.status?if_exists}</td> <td>${todo.purpose?if_exists}</td> <td>${todo.submitDate?datetime?if_exists}</td> </tr> </#if> </#list> </tbody> </table> </#list> <script type="text/javascript"> var st0 = new SortableTable(document.getElementById("todo"), ["String", "String" ,"String" ,"String"]); </script> </div>
最新发布
09-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值