mybatis: No enum constant org.apache.ibatis.type.JdbcType."VARCHAR"

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 即可。

mybatis: No enum constant org.apache.ibatis.type.JdbcType."VARCHAR"

上一篇:C# 连接Mysql读写


下一篇:Mysql之单表查询