сообщение об ошибке:
nested exception is org.apache.ibatis.type.TypeException: Could not set >parameters for mapping: ParameterMapping{property='signIn', mode=IN, >javaType=class java.util.Date, jdbcType=null, numericScale=null, >resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #4 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 (4 > number of parameters, which is 3).
xml
<select id = "selectSignRecordList" parameterType = "SignRecord" resultMap = "SignRecordResult">
<include refid = "selectSignRecordVo"/>
<where>
<if test = "id != null and id != '' "> and id_ = #{id}</if>
<if test = "promiseId != null and promiseId != '' "> and promise_id = #{promiseId}</if>
<if test = "userId != null and userId != '' "> and user_id = #{userId}</if>
<if test = "signIn != null">
and sign_in =#{signIn,jdbcType=DATE}
--and sign_in = date_format( #{signIn} , '%Y-%m-%d' )
-- AND date_format(sign_in,'%y%m%d') = date_format(#{signIn},'%y%m%d')
-- <![CDATA[ and DATE_FORMAT(sign_in, '%Y-%m-%d')= DATE_FORMAT(#{signIn}, '%Y-%m-%d') ]]>
-- AND date(sign_in) = date(#{signIn,jdbcType=DATE})
</if>
<if test = "signStatus != null and signStatus != '' "> and sign_status = #{signStatus}</if>
<if test = "createBy != null and createBy != '' "> and create_by = #{createBy}</if>
<if test = "createTime != null "> and create_time = #{createTime}</if>
<if test = "updateBy != null and updateBy != '' "> and update_by = #{updateBy}</if>
<if test = "updateTime != null "> and update_time = #{updateTime}</if>
<if test = "remark != null and remark != '' "> and remark = #{remark}</if>
</where>
</select>
вход - java.util.Date
Когда я передаю ошибку параметра




Скорее всего, проблема в том, что -- - это начало комментария в SQL, но mybatis об этом не знает. Эта (и все подобные) строчки:
-- AND date(sign_in) = date(#{signIn,jdbcType=DATE})
вызывает проблему, потому что mybatis пытается установить здесь параметр в подготовленном операторе, но ваша СУБД игнорирует эту часть запроса, поэтому этот параметр для нее не существует. Следовательно, появляется сообщение об ошибке, что фактическое количество параметров (известных БД) меньше, чем пытается установить клиент (mybatis).
Чтобы исправить проблему использовать xml-комментарии вместо комментариев SQL, например:
<select id = "selectSignRecordList" parameterType = "SignRecord" resultMap = "SignRecordResult">
<include refid = "selectSignRecordVo"/>
<where>
<if test = "id != null and id != '' "> and id_ = #{id}</if>
<if test = "promiseId != null and promiseId != '' "> and promise_id = #{promiseId}</if>
<if test = "userId != null and userId != '' "> and user_id = #{userId}</if>
<if test = "signIn != null">
and sign_in =#{signIn,jdbcType=DATE}
<!-- and sign_in = date_format( #{signIn} , '%Y-%m-%d' )
AND date_format(sign_in,'%y%m%d') = date_format(#{signIn},'%y%m%d')
<![CDATA[ and DATE_FORMAT(sign_in, '%Y-%m-%d')= DATE_FORMAT(#{signIn}, '%Y-%m-%d') ]]>
AND date(sign_in) = date(#{signIn,jdbcType=DATE})
-->
</if>
<if test = "signStatus != null and signStatus != '' "> and sign_status = #{signStatus}</if>
<if test = "createBy != null and createBy != '' "> and create_by = #{createBy}</if>
<if test = "createTime != null "> and create_time = #{createTime}</if>
<if test = "updateBy != null and updateBy != '' "> and update_by = #{updateBy}</if>
<if test = "updateTime != null "> and update_time = #{updateTime}</if>
<if test = "remark != null and remark != '' "> and remark = #{remark}</if>
</where>
</select>
В этом случае mybatis вообще не будет включать закомментированный фрагмент в SQL-запрос и не будет пытаться установить параметры.