一、创建存储过程
存储过程的目的:统计edi_test_task 正在运行的任务和非运行的任务
CREATE DEFINER=`root`@`%` PROCEDURE `edihelper`.`SP_ISRunning_Count`(IN run_id INT ,OUT num INT)
BEGIN
IF run_id=0 THEN
select count(*) from edi_test_task where is_running=true INTO num;
ELSE
select count(*) from edi_test_task where is_running=false INTO num;
END IF;
END
二、SQL映射文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.cn.mybatis.mapper.taskProMapper">
<!-- 方式一:参数直接写在代码中 -->
<select id="spTkNo" resultMap="Map" statementType="CALLABLE">
CALL edihelper.SP_ISRunning_Count(
#{run_id,jdbcType=INTEGER,mode=IN},
#{num,jdbcType=INTEGER,mode=OUT})
</select>
<!-- 方式二:参数 --> <select id="spTkNo" parameterMap="getTkCountMap" statementType="CALLABLE">
CALL edihelper.SP_ISRunning_Count(?,?)
</select> <parameterMap type="java.util.Map" id="getTkCountMap">
<parameter property="sexid" mode="IN" jdbcType="INTEGER"/>
<parameter property="usercount" mode="OUT" jdbcType="INTEGER"/>
</parameterMap>
</mapper>