大家好,我是一个ssh初学者,遇到的问题是这样的:
    我用hibernate3.2和Struts1.2简单写了一个新闻发布系统,前台每条新闻里面含有网友评论,在后台模块里有一个新闻列表模块,只显示新闻的id、标题、发布者和发布时间,提供对前台的新闻的增删改查,我想在显示新闻标题的同时显示评论的条数,但是我无法使用struts的bean:write取到新闻(Class News)bean中的评论(Class Critique)Set集合的条数,请教各位除了用java代码之外有没有什么好办法?

解决方案 »

  1.   

    直接把set集合在后台的长度传进去。。
    然后EL表达式一步搞定
      

  2.   

    bean:write只是struts的输出标签吧?要计算集合的条数,好像还有个标签吧,我好久不用都忘记了,你看看
      

  3.   


    谢谢你的回复,不单单是一条新闻,我是想在jsp页面中遍历新闻Set,然后再取每条新闻中的评论Set的条数,EL表达式如何能获得Set的size?
      

  4.   

    数据库层建一个视图,统计每个新闻的评论条数,前台Hibernate中关联查询
      

  5.   

    <bean:size>用于获得Map、Collection或者数组的长度。包括以下属性:id: 定义一个Integer类型的变量name: 指定已经存在的Map、Collection或者数组变量例如: <bean:size id="length" name="list"/><bean:write name="length"/>
      

  6.   


    <form action="">
       <table width="70%" cellspacing="0" cellpadding="3">
      <tr>
        <th width="5%" scope="col">编号</th>
        <th width="10%" scope="col">类型</th>
        <th width="40%" scope="col">标题</th>
        <th width="25%" scope="col">时间</th>
        <th width="8%" scope="col">作者</th>
        <th width="7%" scope="col">操作</th>
      </tr>
      <logic:present name="NEWS_LIST">
       <logic:iterate id="News" name="NEWS_LIST">
      <tr>
        <td><div align="center"><bean:write name="News" property="id" /></div></td>
        <td><div align="center"><bean:write name="News" property="newstype.name" /></div></td>
        <td><div align="center"><a href="newsview.do?type=view&&id=<bean:write name="News" property="id" />"><bean:write name="News" property="title" />(<a href="#">评论条数</a>)评论</div></td>
        <td><div align="center"><bean:write name="News" property="posttime" format="MM-dd HH:mm"/></div></td>
        <td><div align="center"><bean:write name="News" property="author.name" /></div></td>
        <td><div align="center">[<a href="newsdel.do?type=del&&id=<bean:write name="News" property="id" />">删除</a>][<a href="newsedit.do?type=edit&&id=<bean:write name="News" property="id" />">编辑</a>]</div></td>
      </tr>
    </logic:iterate>
      </logic:present>
    </table>
      </form>