MyBatis错误之nested exception is org.apache.ibatis.type.TypeException

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xintonghanchuang/article/details/89186622

今天在调试项目中的某个功能时发现代码报错:

nested exception is org.apache.ibatis.type.TypeException: 
Could not set parameters for mapping: ParameterMapping{property='ACTION_NM', mode=IN, javaType=class java.lang.Object, jdbcType=NVARCHAR, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}.
 Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #4 with JdbcType NVARCHAR . Try setting a different JdbcType for this parameter or a different configuration property. 
 Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #4 with JdbcType NVARCHAR . Try setting a different JdbcType for this parameter or a different configuration property. 
 Cause: com.microsoft.sqlserver.jdbc.SQLServerException: The index 4 is out of range.

仔细查看Mapper文件后发现SQL中有如下语句:

<if test="DOCID != null and DOCID !=''"> 
       		AND (FH.DOCID = #{DOCID,jdbcType=DECIMAL}
       		OR FH.O_DOCID = #{DOCID,jdbcType=DECIMAL} )
       		--OR (FH.POLICY_NO in (select distinct POLICY_NO from FS_BIS_DOCUMENT where documentid =#{DOCID,jdbcType=DECIMAL}) and FH.DOCID is null)
      	</if> 

才发现同事在粘贴SQL时将SQL Server中的注释粘贴过来了,造成了此项错误。
注意:在MyBatis中的注释格式是如下:

<if test="DOCID != null and DOCID !=''"> 
       		AND (FH.DOCID = #{DOCID,jdbcType=DECIMAL}
       		OR FH.O_DOCID = #{DOCID,jdbcType=DECIMAL} )
       		<!-- OR (FH.POLICY_NO in (select distinct POLICY_NO from FS_BIS_DOCUMENT where documentid =#{DOCID,jdbcType=DECIMAL}) and FH.DOCID is null) -->
      	</if> 

猜你喜欢

转载自blog.csdn.net/xintonghanchuang/article/details/89186622