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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM