예외: Could not set parameters for mapping: ParameterMapping {property='xxx', 모델=XX, ·····}
23981 단어 코드 예외
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` (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})
*/
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})
-->
}