环境: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>