1、在前端页面做添加货物的数据时,将前端的数据返回到Controller的方法,执行下一步就出现以下的异常:
java.lang.RuntimeException: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='amount', mode=IN, javaType=class java.lang.Double, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #16 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: Parameter index out of range (16 > number of parameters, which is 15).
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='amount', mode=IN, javaType=class java.lang.Double, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #16 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: Parameter index out of range (16 > number of parameters, which is 15).
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:77)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)
at com.sun.proxy.$Proxy17.insert(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:278)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:57)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
at com.sun.proxy.$Proxy18.addContractProductList(Unknown Source)
2、原来是在MyBatis的Mapper.xml文件中,注释了添加货物数据的SQL语句,同时也写了添加货物数据的动态SQL语句,这里是注释使用不正确
<!-- 添加货物的数据 -->
<insert id="addGoodsList">
INSERT INTO `goods`
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
<if test="contractId != null">contract_id,</if>
<if test="factoryId != null">factory_id,</if>
<if test="factoryName != null">factory_name,</if>
<if test="productNo != null">product_no,</if>
<if test="productImage != null">product_image,</if>
<if test="productDesc != null">product_desc,</if>
<if test="price != null">price,</if>
<if test="amount != null">amount,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id,jdbcType=VARCHAR},</if>
<if test="contractId != null">#{contractId,jdbcType=VARCHAR},</if>
<if test="factoryId != null">#{factoryId,jdbcType=VARCHAR},</if>
<if test="factoryName != null">#{factoryName,jdbcType=VARCHAR},</if>
<if test="productNo != null">#{productNo,jdbcType=VARCHAR},</if>
<if test="productImage != null">#{productImage,jdbcType=VARCHAR},</if>
<if test="productDesc != null">#{productDesc,jdbcType=VARCHAR},</if>
<if test="price != null">#{price,jdbcType=DECIMAL},</if>
<if test="amount != null">#{amount,jdbcType=DECIMAL},</if>
</trim>
</insert>
3、MyBatis的Mpper.xml文件,支持的注释格式是 ,需要将上面/**/
注释格式换成
<!--
INSERT INTO `goods` (id,contract_id,factory_id,factory_name,product_no,product_image,product_desc,price,amount)
VALUES (#{id},#{contractId},#{factoryId},#{factoryName},#{productNo},#{productImage},#{productDesc},#{price},#{amount})
-->
}