mybatis 插入的時候一句sql報錯如下。
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.BuilderException: Error resolving JdbcType. Cause: java.lang.IllegalArgumentException: No enum constant org.apache.ibatis.type.JdbcType."VARCHAR"
insert into sys_user( <if test="userId != null and userId != '' ">user_id,</if> create_time )values( <if test="userId != null and userId != ''">#{userId,jdbcType="VARCHAR"},</if> sysdate )
原因在於
#{userId,jdbcType="VARCHAR"},
即mybatis所定義的類型常量枚舉不存在,mybatis 解析為了"VARCHAR" 帶雙引號的字符串,改為
insert into sys_user( <if test="userId != null and userId != '' ">user_id,</if> create_time )values( <if test="userId != null and userId != ''">#{userId,jdbcType=VARCHAR},</if> sysdate )
把雙引號去掉或者直接不寫jdbcType 即可。