SSH如何获取外键表ID对应的Name问题,并在页面显示
本帖最后由 lvbolvtian 于 2011-08-03 16:14:30 编辑 问题如题。
是这么一个情况:
有一个数据库表:
quesitiontbl问题表,用于存储 某个人 发布的问题,
表里面有部分字段(id主键,content问题内容,SystemMembeID外键表示谁发的问题)
外键表 systemmembertbl,部分字段(id主键,name发布人的姓名)
然后我构建了对应的实体类,以及映射文件,下面就是Question类的映射文件部分内容。
sm是定义在Question类里面的SystemMember类的一个实例。问题与发布者为多对一的关系
<many-to-one name="sm" class="com.mytest.entity.SystemMember">
<column name="systemmemberid" ></column>
</many-to-one>
public String listQuestion() throws Exception {
// TODO Auto-generated method stub
String hql="from Question";
questionsList= basedao.list(hql);
return SUCCESS;
}
<table>
<s:iterator value="#request.questionsList">
<tr>
<td><s:property value="sm.id" /></td>
<td><s:property value="content" /></td>
</tr>
</s:iterator>
</table>
<td><s:property value="sm.name" /></td>
<td><s:property value="content" /></td>