1. 程式人生 > >Mybatis報錯___入參異常導致

Mybatis報錯___入參異常導致

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException:
Could not set parameters for mapping: ParameterMapping
{property='docNo', mode=IN, javaType=class java.lang.String, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}.
Cause: org.apache.ibatis.type.TypeException: Error setting null for parameter #1 with JdbcType OTHER .
Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property.
Cause: java.sql.SQLException: 無效的列型別: 1111
    at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:77)
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)
    at com.sun.proxy.$Proxy116.selectOne(Unknown Source)
    at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:166)
    at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:82)
    at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
    at com.sun.proxy.$Proxy122.getDeptNameByDocNoBydocNo(Unknown Source)
    at com.group.emr.heren.dao.oracle.PatientDao.setHospitalPatient(PatientDao.java:233)

------------------------------------------------------------------------------

上面是自己專案中碰到的問題;

原因:

DefaultParameterHandler類在解析引數的時候,無法解析引數型別,指定預設的型別OTHER.

解決辦法:

解決辦法:

 在insert或update語句中,增加jdbcType指定欄位的型別

如:

  <![CDATA[

  insert into t_yp_province

  (fid,fname,fnumber,fsimpleName,fdescription,fcreateTime,flastUpdateTime,fdirect)

  values

  ( #{id,jdbcType=VARCHAR},

   #{name,jdbcType=VARCHAR},

   #{number,jdbcType=VARCHAR},

   #{simpleName,jdbcType=VARCHAR},

   #{description,jdbcType=VARCHAR},

   #{createTime,jdbcType=DATE},

   #{lastUpdateTime,jdbcType=DATE},

   #{direct,jdbcType=NUMERIC}

  )  

  ]]>

 </insert>;

 

轉自:https://www.cnblogs.com/havery/articles/4025879.html    並結合自己碰到的