<logic:iterate>同for循环的用法比较

18 篇文章 0 订阅
同样生成一个Table

<table id="checkTable" align="center" cellpadding="5" cellspacing="0" border="0" width="100%">
<tbody>
<logic:iterate id="item" name="list" type="com.worthtech.app.bean.User" indexId=" index">
<%
  //int index=((java.lang.Integer)pageContext.findAttribute("index")).intValue();//自增的索引,相当于for里面的i,logic:iterate里用起来比较麻烦,红色部分必须一致
  if(( index%2)==0){//斑马线
  %>
    <tr class="SelcetOff">
  <%}else{%>
    <tr class="SelcetOn">
  <%}%>
     <td><div align="center"><bean:write name="item" property="userName"/></div></td>
     <td><div align="center"><bean:write name="item" property="address"/></div></td>
         
        </tr>
</logic:iterate>
</tbody>
</table>


<table id="checkTable" align="center" cellpadding="5" cellspacing="0" border="0" width="100%">
<tbody>
 <%
 if (request.getAttribute("list") != null) {
	java.util.List l = (java.util.List) request.getAttribute("list");
	  for (int i = 0; i < l.size(); i++) {
               com.worthtech.app.bean.User user = (com.worthtech.app.bean.User) l.get(i);
	       if(i%2==0){//斑马线
                 out.print("<tr class='SelcetOff'>");
               }else{
                 out.print("<tr class='SelcetOn'>");
               }								
         	out.print("<td><div align='center'>"+ user.getUserName() + "</div></td>");
		out.print("<td><div align='center'>"+ user.getAddress() + "</div></td>");
		out.print("</tr>");
	}
}
%>
</tbody>
</table>



用for循环比较自由度大,方便。比如要对user.getAddress()进行操作,可以out.print("<td><div align='center'>"+ Util.parse(user.getAddress()) + "</div></td>");
如果使用<logic:iterate>里的<bean:write name="item" property=" address"/>就必须这样:
<bean:define id="var" name="item" property=" address" type="java.lang.String"/>
<% java.lang.String address=var;%>
<td><div align="center"><%=Util.parse(address) %></div></td>
这样显得很麻烦。
总结:使用<logic:iterate>灵活度不高
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值