当前位置: 代码迷 >> Java Web开发 >> hibernate一对多怎么遍历显示主子表内容
  详细解决方案

hibernate一对多怎么遍历显示主子表内容

热度:4155   发布时间:2013-02-25 21:19:14.0
hibernate一对多如何遍历显示主子表内容
刚学SSH2框架,应该是个很简单的问题。
我有两个表。 问题表Question 和 答案表Answer. 是一对多的关系。表Question映射中有个set集合  
<set name="answers" inverse="true" cascade="all" lazy="false" order-by="ANSWER_MARK">
<key column="QUES_ID"/>
<one-to-many class="Answer"/>
</set>
我现在想把两个表内容都显示出来,就是一条问题跟着几个答案(就是试卷那样)。
sql语句就是"from Question"
在Action中我把结果放在了List questions中  
在JSP页面中我遍历questions
<s:iterator value="questions" status="liststat">
  <tr><td><s:property value="#liststat.index+1"/>,
<s:property value="question"/></td></tr>
</s:iterator>  
那么我如何把set中的内容也遍历出来呢就是怎么把答案显示出来?
好像是不是要把结果questions封装到map中?怎么封装呢?
在做毕业设计老师完全不理我,唉。大家帮帮我啊。

------解决方案--------------------------------------------------------
探讨
刚学SSH2框架,应该是个很简单的问题。
我有两个表。 问题表Question 和 答案表Answer. 是一对多的关系。表Question映射中有个set集合
<set name="answers" inverse="true" cascade="all" lazy="false" order-by="ANSWER_MARK">
<key column="QUES_ID"/>
<on……
  相关解决方案