为了账号安全,请及时绑定邮箱和手机立即绑定

我最后想得到这些个数字,怎么样做呢?

我最后想得到这些个数字,怎么样做呢?

PHP
翻翻过去那场雪 2023-03-12 20:16:40
我是用struts,hibernate,spring编程的,想显示所有的数据,比如数据库中共有3行数据,我想将这三行数据的每个属性都显示出来,当然是不用form的,第一,我不知道是不是用DAO里提供的findAll()函数,第二,如果是的话,返回值是一个List,那么,我如何将一个list中的数据,重新分开成为我想要的数据比如:数据库有三个属性a,b,c,有三行数据(1,2,3)(4,5,6)(7,8,9)我最后想得到这九个数字,怎么样做呢?
查看完整描述

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<对象名>的集合

查看完整回答
反对 回复 2023-03-15
?
MM们

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 兄弟 还得继续学啊


查看完整回答
反对 回复 2023-03-15
  • 2 回答
  • 0 关注
  • 128 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号