关于Ibatis的一个问题,求解答

yanglei031 2011-10-09 02:52:59
<typeAlias alias="userVO" type="com.test.userVO" />

<resultMap id="userVOResult" class="userVO">


<result property="code" column="fcode" />

<result property="name" column="fname" />

<result property="birthday" column="fbirthday" />

<result property="value" column="fvalue" />



</resultMap>


<select id="sqlQuery1" parameterClass="java.util.Date"
resultMap="userVOResult">

select fcode,fname,fbirthday,fvalue
from t_user where fbirthday = #fbirthday#
</select>

<select id="sqlQuery2" parameterClass="java.util.Date"
resultMap="userVOResult">

select fcode,fbirthday,fvalue
from t_user where fbirthday = #fbirthday#
</select>

在sqlQuery1中定义了返回的结果用resultMap来映射,这样是没问题的,因为sqlQuery1中所有的字段都在resultMap有定义,
但是用sqlQuery2查询就出错了,报错信息如下:(sqlQuery2中没有查name字段,但在resultMap有定义,)
--- Check the result mapping for the 'name' property.
--- Cause: java.sql.SQLException: 列名无效
Caused by: java.sql.SQLException: 列名无效

是不是在sql中定义的所有字段在resultMap都必须定义?
如果是上面这种情,其实查询的结果是一样,可是可能会少一些字段,这种情况我就一定要定义2个resultMap嘛?
...全文
119 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
yanglei031 2011-10-10
  • 打赏
  • 举报
回复
谢谢了,你的方法我也想过这样,但是最终还是不太合适,每个查询都得把resultMap 定义的字段都取出来,也很麻烦,今天看了一下ibatis的源码,他们根据resultMap 中定义的字段去rs中匹配的,所以这应该是没办法解决的。
wby13579 2011-10-10
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 yanglei031 的回复:]
引用 1 楼 wby13579 的回复:
select fcode,fbirthday,fvalue,name nullfrom t_user where fbirthday = #fbirthday#


大哥,你这样写sql都有语法错误啊.....
[/Quote]

呵呵抱歉抱歉
select fcode,fbirthday,fvalue,null name from t_user where fbirthday = #fbirthday#
应该这样
yanglei031 2011-10-09
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 wby13579 的回复:]
select fcode,fbirthday,fvalue,name nullfrom t_user where fbirthday = #fbirthday#
[/Quote]

大哥,你这样写sql都有语法错误啊.....
wby13579 2011-10-09
  • 打赏
  • 举报
回复
select fcode,fbirthday,fvalue,name nullfrom t_user where fbirthday = #fbirthday#

50,528

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧