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