错误
org.springframework.jdbc.UncategorizedSQLException: 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
; uncategorized SQLException for SQL []; SQL state [99999]; error code [17004]; 无效的列类型: 1111; nested exception is java.sql.SQLException: 无效的列类型: 1111
原因
当参数为null时,对于mybatis,如果进行操作的时候,没有指定jdbctype类型的参数,mybatis指定的默认jdbctype=other将会抛出异常
解决
#{参数名,jdbcType=指定类型}
- 指定jdbcType即可
报错写法
<if test="importTime != null and importTime != '' ">and t1.IMPORT_TIME = #{importTime}</if>
正确写法
<if test="importTime != null and importTime != '' ">and t1.IMPORT_TIME = #{importTime,jdbcType=DATE}</if>
- 注意事项
jdbcType是有严格大小写规范的,这里要用大写