如果你是用struts+hibernate开发的话,那以下就是你的例子:  jsp代码如下:<logic:present name="forum">
<logic:notEmpty name="forum">
<logic:iterate id="r" name="forum"> <table width=100% align=center bordercolor="#D8F8F8" class=tableborder>
<tbody>
<tr>
<td class=header colspan=6>
<img src="../image/collapsed_yes.gif" />
<bean:write name="r" property="title" />
</td>
</tr>
<tr class="category" height="1">
<td width="30%" align="left">
论坛
</td>
<td width="10%">
今天人气
</td>
<td width="10%">
帖数
</td>
<td width="30%">
最后发表
</td>
<td width="20%">
<a
href="javascript:openset('../topic/applyBZ.jsp','450','450')"
align="center"> <img src="<%=cp%>/image/bz.gif" border="0" />
版主</a>
</td>
</tr>
<br />
<logic:iterate id="block" name="r" property="forumBlocks">
<tr class="font" height="1">
<td width="30%" align="left" class=bold>
<html:link action="newmoretopic" paramId="x" paramName="block"
paramProperty="id0" target="_parent">
<logic:equal name="block" property="forumStatus" value="0">
<img src="../image/newpokp1.gif" width="20" height="20"
border="0" />
</logic:equal>
<logic:equal name="block" property="forumStatus" value="1">
<img src="../image/newpokp.gif" width="20" height="20"
border="0" />
</logic:equal>
<bean:write name="block" property="forumName" />
</html:link>
<br />
<div class="category">接口-类的继承...</div>
</td>
<td width="10%">
<bean:write name="block" property="todayTotal" />
</td>
<td width="10%">
<bean:write name="block" property="total" />
</td>
<td width="30%">
<bean:write name="block" property="latestTopicAddTime"
format="yyyy-MM-dd HH:mm:ss"/><br />
&nbsp;&nbsp;by
<html:link action="preguestdetail" paramId="x"
paramName="block" paramProperty="latestTopicAuthorName"
target="_blank">
&nbsp;&nbsp;<bean:write name="block" property="latestTopicAuthorName" />
</html:link>
</td>
<td width="20%">
<html:link page="/start/persondetail.jsp">
<logic:iterate name="block" property="bzs" id="bz">
<html:link action="preguestdetailusername" paramId="x"
paramName="bz" paramProperty="username" target="_blank">
<bean:write name="bz" property="username" />&nbsp;&nbsp;</html:link>
</logic:iterate>
</html:link>
</td>
</tr>

</logic:iterate> </tbody>
</table>
</logic:iterate>
</logic:notEmpty>
<logic:empty name="forum">
<tr>
<td colspan="1">
存在,但无论坛记录!
</td>
</tr>
</logic:empty>
</logic:present>
<logic:notPresent name="forum">
<tr>
<td colspan="1">
!
</td>
</tr>
</logic:notPresent>
   java代码如下:Vector aList2 = getForumTypes(hs);
sess.setAttribute("forum", aList2);
return mapping.findForward("s");
}
// 取得主分区数
private int getForumType(Session hs){
int rs=0;
Query countSQL =hs.createQuery("select count(*) from Forumtype where del=0");
rs=((Integer)countSQL.list().get(0)).intValue();
return rs;
}
//  取得子分区总数
private int getForumBlock(Session hs){
int rs=0;
Query countSQL = hs.createQuery("select count(*) from Forumblock where del=0");
rs=((Integer)countSQL.list().get(0)).intValue();
return rs;
}
// 取得当天的bbstopics数
private int getTotayTotal(Session sess){
int rs =0;
Query countSQL = sess.createQuery("SELECT count(*) FROM Topic where date_format(addtime,'%Y-%m-%d')=date_format(now(),'%Y-%m-%d')" );
rs = ((Integer)countSQL.list().get(0)).intValue();
return rs;
}

//统计主题数 
private int getTotalTopics(Session hs){
int rs=0;
Query countSQL = hs.createQuery("select count(*) from Topic");
rs = ((Integer)countSQL.list().get(0)).intValue();
return rs;
}
// 统计jinghua主题数 
private int getTotalGoodTopics(Session hs){
int rs=0;
Query countSQL = hs.createQuery("select count(*) from Topic where kind="+2);
rs = ((Integer)countSQL.list().get(0)).intValue();
return rs;
}
//统计昨日帖数
private int getYesterdayTotal(Session hs){
int rs=0;
Query countSQL = hs.createQuery("SELECT count(*) from Topic WHERE TO_DAYS(NOW()) - TO_DAYS(addtime) = 1" );
rs = ((Integer)countSQL.list().get(0)).intValue();
return rs;
}
// 统计会员总数
private int getMembers(Session hs){
int rs=0;
Query countSQL =hs.createQuery("select count(*) from User");
rs=((Integer)countSQL.list().get(0)).intValue();
return rs;
}
//统计指定版块的昨日帖数
private int getYesterdayTotal(Session hs, int fbSeqNo){
int rs=0;
Query countSQL = hs.createQuery("SELECT count(*) from Topic WHERE TO_DAYS(NOW()) - TO_DAYS(addtime) = 1 where BbsForumBlockSeqNo="+fbSeqNo);
rs = ((Integer)countSQL.list().get(0)).intValue();
return rs;
}
//统计总帖数包括主题和回复的
private int getAllTotal(Session hs){
int rs1 =0,rs2=0;
rs1=getTotalTopics(hs);
Query countSQL = hs.createQuery("select count(*) from Topicreply where del=0");
        rs2=((Integer)countSQL.list().get(0)).intValue();
        return rs1+rs2;
}

private Vector getForumTypes(org.hibernate.Session hs){
Vector forumTypes = new Vector();
Criteria crit1 = hs.createCriteria(Forumtype.class).add(Restrictions.eq("del",(byte)0)).addOrder(Order.desc("id0")).setMaxResults(4);
List lst1 = crit1.list(); 
for(int i=0; i<lst1.size(); i++){
Forumtype ft = (Forumtype)lst1.get(i);
hs.refresh(ft);
Set forumBlocks = ft.getForumblocks();  
VOBBSForumType vft = new VOBBSForumType();
vft.setTitle(ft.getTitle()); vft.setSeqNo(ft.getId0());  vft.setAddtime(ft.getAddtime().toString()); 

Vector vfbs = new Vector();
Iterator forumBlocksIt = forumBlocks.iterator();
while(forumBlocksIt.hasNext()){
Forumblock fb = (Forumblock)forumBlocksIt.next();
hs.refresh(fb);
//=======================
ForumBlockUtil fbu = new ForumBlockUtil();
VOBBSForumBlock vfb = fbu.getVOBBSForumBlock(fb);
vfbs.add(vfb);
}
vft.setForumBlocks(vfbs);
forumTypes.add(vft);
}
return forumTypes;
}

解决方案 »

  1.   

    希望可以帮到你!如果不清楚的话,可以[email protected]给我,可以互相交流交流!
      

  2.   

    另外问你一下,你是不是余铭他哥?是就请加我    [email protected]
      

  3.   

    你说的那个人不是我
    我是想显示"最后发表的那个帖子的时间"和"发表这个帖子的作者名"
    关于这个功能,数据库表应该如何设计?javabean中的属性应该如何写?hibernate配置文件如何映射?
      

  4.   


              字段                              字段
    版块表:  id                 主题帖子表:  帖子id
             名字                            标题
             版块说明                        主题内容
             最后更新时间                    用户id    (外健引用用户表主见)
             最后更新作者                    帖子发表时间
                                             版块id    (外健,引用版块表主见)当增加主题帖子记录的时候自动更新版块表的最后更新时间和最后更新作者这两个字段,hibernate能实现吗?怎么实现?映射文件怎么写?版块类和主题帖子类怎么设计?