日期:2014-05-20  浏览次数:20791 次

ibatis查询时,返回类型中有其他对象,映射xml文件中怎么写?
有一张user表,有userID typeName 字段 ,其中typeName 是 type表中的字段
我建实体类时先创建了Type类然后,User类中包含了Type类的对象。

在user.xml文件中写查询全部user表信息时
<select id="getAllUser" resultClass="User">
  select * from user
</select>

会报错
--- The error occurred in User.xml.  
--- The error occurred while applying a result map.  
--- Check the getAllUser-AutoResultMap.  
--- Check the result mapping for the 'type' property.

我想是因为我设置的返回类型是User。但是User对象中的type属性不能够接收,ibatis查询User表时查到的typeName
我尝试着 
<select id="getAllUser" resultClass="User">
  select userID,type.typeName from user
</select>
会报错说:
--- Cause: java.sql.SQLException: ORA-00904: "type"."typeName":标识符无效
有什么解决方法呀??

------解决方案--------------------
看文档里的ResultMap
------解决方案--------------------
Java code

<resultMap type="java.util.HashMap" id="User">
<result column="id" property="id"></result>
<result column="name" property="name"></result>
<result column="age" property="age"></result>
</resultMap>

<select id="getUser" resultMap="User">
SELECT id,name,age FROM  user
</select>

------解决方案--------------------
探讨
Java code