SpringBoot+Mybatis+MySQL,调用存储过程报错解决办法:No enum constant org.apache.ibatis.type.JdbcType.Integer

本文解决了一个关于在Mybatis中调用存储过程时出现的错误:Noenumconstantorg.apache.ibatis.type.JdbcType.Integer。通过修正SQL语句中的jdbcType属性值,将Integer改为INTEGER,成功解决了问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

环境:IDEA+SpringBoot+Mybatis+MySQL

 

今天在mapper.xml文件中调用存储过程的时候发现如下报错:

No enum constant org.apache.ibatis.type.JdbcType.Integer

 

报错时,我的SQL语句是:

<!--存储过程的调用统一使用select节点,同时要明确指定statementType="CALLABLE"-->
  <select id="deleteDepById" parameterType="com.zzz.vuehr.bean.Department" statementType="CALLABLE">
    call deleteDep(#{id,mode=IN,jdbcType=Integer},#{result,mode=OUT,jdbcType=Integer})
  </select>

对应保存在MySQL中的存储过程是:(输入的变量名为"id",输出的变量名为"result")

begin
  declare ecount int;
  declare pid int;
  declare pcount int;
  declare a int;
  select count(*) into a from department where id=did and isParent=false;
  if a=0 then set result=-2;
  else
  select count(*) into ecount from employee where departmentId=did;
  if ecount>0 then set result=-1;
  else 
  select parentId into pid from department where id=did;
  delete from department where id=did and isParent=false;
  select row_count() into result;
  select count(*) into pcount from department where parentId=pid;
  if pcount=0 then update department set isParent=false where id=pid;
  end if;
  end if;
  end if;
end

执行的时候,详细报错信息是:

nested exception is java.lang.IllegalArgumentException: org.apache.ibatis.builder.BuilderException:

Error parsing Mapper XML. The XML location is 'com/zzz/vuehr/mapper/DepartmentMapper.xml'.

Cause: org.apache.ibatis.builder.BuilderException: Error resolving JdbcType.

Cause: java.lang.IllegalArgumentException: No enum constant org.apache.ibatis.type.JdbcType.Integer
 

大意就是我的DepartmentMapper.xml这个文件出错了,因为找不到一个叫Integer的枚举常量。

 

解决流程:

1、连续按两次Shift键,开启IDEA的全局搜索,并搜索JdbcType,查找给定的常量。

2、结果发现给定的枚举常量为INTEGER,而不是Integer

 

3、最后把SQL语句改正成如下的,就好了

  <!--存储过程的调用统一使用select节点,同时要明确指定statementType="CALLABLE"-->
  <select id="deleteDepById" parameterType="com.zzz.vuehr.bean.Department" statementType="CALLABLE">
    call deleteDep(#{id,mode=IN,jdbcType=INTEGER},#{result,mode=OUT,jdbcType=INTEGER})
  </select>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值