首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

ibatis查询时,返回类型中有其他对象,映射xml文件中如何写

2012-02-03 
ibatis查询时,返回类型中有其他对象,映射xml文件中怎么写?有一张user表,有userID typeName 字段 ,其中type

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

热点排行