1. 程式人生 > >Invalid bound statement (not found) 異常原因

Invalid bound statement (not found) 異常原因

mybatis報錯如下:
org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [dispatcherServlet] in context with path [/zc-beauty2]   
threw exception [Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):  
 com.zc.beauty.dao.ICaptchaMapper.savePhoneCode] with root cause  
 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): 

原因如下:

1、沒有載入mapper檔案:

<mappers>  
        <mapper resource="mappers/CaptchaMapper.xml" />  
</mappers> 

2、介面路徑問題:
<!-- 這裡namespace必須是介面的路徑,不然要執行的時候要報錯 “is not known to the MapperRegistry”-->  
<mapper namespace="com.zc.beauty.dao.ICaptchaMapper"> 

3、沒有對映:
<bean id="CaptchaMapper" class="org.mybatis.spring.mapper.MapperFactoryBean" >  
       <property name="sqlSessionFactory" ref="SqlSessionFactory" />  
       <property name="mapperInterface" value="com.zc.beauty.dao.ICaptchaMapper" />  
   </bean> 

4、DAO層方法名和xml中的id不同
<!-- 這裡的id必須和介面中的方法名相同,不然執行的時候也要報錯 -->  
   <insert id="savePhoneCode" parameterType="com.zc.beauty.model.PhoneCaptcha">  
       insert into phone_captcha(u_phone, c_phonecode, c_sendtime) values(#{u_phone}, #{c_phonecode}, #{c_sendtime})  
   </insert>

5、返回型別resultMap在xml中未宣告
<resultMap id="RecsortChnResultMap" type="com.caissa.erp.caissafip.domain.basic.recsortchnconfig.po.RecsortChnConfigVo" >
    <id column="DBID" property="dbid" jdbcType="CHAR" />
    <result column="FK_RECCHN_DBID" property="fkRecchnDbid" jdbcType="CHAR" />
    <result column="UPDATEDEPTNAME" property="updatedeptname" jdbcType="VARCHAR" />
  </resultMap>
<select id="selectChnRectypeByConfigDbid" resultMap="ChnRectypeResultMap" parameterType="java.lang.String">
		SELECT 
			CRR.DBID, recsort.RECSORTNAME,  chn.CHNNAME,  rectype.RECTYPENAME,CRR.FK_CONFIG_DBID,CRR.FK_RECTYPE_DBID,rcconfig.FK_RECCHN_DBID,rcconfig.FK_RECSORT_DBID,rcconfig.ISRECEIVABLE,rcconfig.RECEIVABLECOMPANYCODE,rcconfig.RECEIVABLECOMPANYNAME
			FROM FI_BS_CHN_RECTYPE_REF CRR 
			LEFT JOIN FI_BS_RECSORT_CHN_CONFIG rcconfig on CRR.FK_CONFIG_DBID = rcconfig.dbid
			left join FI_DC_RECEIVESORT recsort on recsort.dbid = rcconfig.FK_RECSORT_DBID and recsort.delflag = '1'
			left join FI_BS_CHN chn on chn.dbid = rcconfig.FK_RECCHN_DBID and chn.delflag = '1' 
			left join FI_DC_RECEIVETYPE rectype on rectype.dbid = crr.FK_RECTYPE_DBID and rectype.delflag = '1'
			WHERE RCCONFIG.DELFLAG = '1' AND CRR.DELFLAG = '1'
		AND RCCONFIG.DBID = #{fkConfigDbid, jdbcType=VARCHAR}
  </select>