您的位置:首页 > 其它

ibatis 复杂类型属性(自定义类型的属性)

2011-06-21 14:04 323 查看
工作需要,看了很多资料,网上大都都是你抄我我抄你,一个bug改了N次都不成功,最后终于运行出来了一个,现在做一下总结

首先,我的两个表tablea和tableb

tablea: String id;

String nameid;

tableb: String nameid;

String name;

然后,VO类

tablea:String id

String nameid;

tableb name;

tableb:String nameid;

String name;

sqlmap配置:

<sqlMap namespace="testquestion">
<resultMap id="tablea" class="net.winclass.modules.testquestion.vo.tablea" >
<result property="id" column="id"/>
<result property="nameid" column="nameid"/>
<result property="name" column="nameid" select="testquestion.tableb_sel"/>
</resultMap>
<resultMap id="tableb" class="net.winclass.modules.testquestion.vo.tableb" >
<result property="nameid" column="nameid"/>
<result property="name" column="name"/>
</resultMap>

<select id="tableb_sel" parameterClass="String" resultMap="tableb">
select * from tableb where nameid=#value#
</select>

<select id="tablea_sel" parameterClass="String" resultMap="tablea">
select * from tablea where id=#value#
</select>
</sqlmap>


Dao应用层代码:

@Override
public tablea selectall()
{

return (tablea)getSqlMapClientTemplate().queryForObject("testquestion.tablea_sel","1");
}


页面显示代码:

<%
tablea list= (tablea)request.getAttribute("selectall");
%>
ID:<%=list.getId()%>
姓名ID:<%=list.getNameid() %>
姓名:<%=list.getName().getName() %>


运行通过,但是现在的问题是,只能显示单条数据

革命尚未成功,仍需继续努力!加油~
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: