这是个广告不要点击哈哈哈

随笔 - 42  文章 - 0  评论 - 14  阅读 - 14万 

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

posted on   水流花落  阅读(4948)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
点击右上角即可分享
微信分享提示