2 回答

TA貢獻1799條經驗 獲得超9個贊
List集合里存儲的是你hibernate model對象(也就是你由類對應的一行記錄)
可以用c:foreach 或是 struts迭代標簽
既然你說的是ssh,那么說一下struts的標簽
<logic:iterate id="..." name="..." indexId="i">
<bean:write name="i">
<bean:write name="id的值" property="對象里面的字段名">
</logic:iterate>
name為你的list名稱,id可以隨便取,indexID為遍歷到第幾條記錄數.
關鍵是hql查詢結果list要賦給一個帶范行list<對象名>的集合

TA貢獻1886條經驗 獲得超2個贊
給你看段代碼
<logic:empty name="proList" scope="request">暫時沒有此類商品</logic:empty>
<logic:notEmpty name="proList" scope="request">
<logic:iterate id="pro" name="proList" scope="request">
<tr>
<td>
<table width="603" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="150" height="135" align="center" background="images/cp001.gif" ><img src="manage/product/images/<bean:write name="pro" property="photoAdd"/>" width="140" height="125" /></td>
<td width="15" valign="top"> </td>
<td width="438" valign="top"><table width="438" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="zi_xh"><bean:write name="pro" property="title"/></td>
</tr>
<tr>
<td class="zi_12" height="88" valign="top"><bean:write name="pro" property="content" filter="false"/></td>
</tr>
<tr>
<td class="zi_12" align="right"><a href="products.do?method=getProducts&proCate=<bean:write name="pro" property="TCProductsCategory.categoryId"/>&proId=<bean:write name="pro" property="id"/>"><img src="images/sy009.gif" width="76" height="18" border="0" /></a></td>
</tr>
</table></td>
</tr>
<tr>
<td height="8" colspan="3"></td>
</tr>
</table>
</td>
</tr>
</logic:iterate>
</logic:notEmpty>
是不是不明白?
問題的關鍵是你要學會struts標簽 它提供了很強大的功能其中就包括迭代list 上面的代碼就是迭代list 兄弟 還得繼續學啊
- 2 回答
- 0 關注
- 117 瀏覽
添加回答
舉報