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

关于Ibatis的一个问题,求解答
<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嘛?


------解决方案--------------------
select fcode,fbirthday,fvalue,name nullfrom t_user where fbirthday = #fbirthday#