Mybatis 执行存储过程,获取输出参数的值
数据库环境:SQL Server 2008 R2
存储过程
alter procedure proc_generateOuterApplyId @acceptType varchar(4),@acceptGroupId int,@outerApplyId varchar(20) output
as
begin set nocount onset @outerApplyId = '24GD6688'--select @outerApplyId as outerApplyIdset nocount off
end
service
// 通过受理类别、受理组别,生成当前最大流水号的受理编号@Overridepublic String generateOuterApplyId(String acceptType, Integer acceptGroupId) {HashMap<String, Object> map = new HashMap<String, Object>();map.put("acceptType", acceptType);map.put("acceptGroupId", acceptGroupId);map.put("outerApplyId", "");// 执行存储过程applyBasicInfoMapper.generateOuterApplyId(map);// 获取输出参数 outerApplyId 的值return map.get("outerApplyId").toString();}
mapper
// 通过受理类别、受理组别,生成当前最大流水号的受理编号// 执行存储过程,获取输出参数 outerApplyId 的值void generateOuterApplyId(HashMap<String, Object> map);
xml
<!--通过受理类别、受理组别,生成当前最大流水号的受理编号--><!--执行存储过程,获取输出参数 outerApplyId 的值--><select id="generateOuterApplyId" resultType="java.lang.Object" parameterType="java.util.HashMap" statementType="CALLABLE">execute proc_generateOuterApplyId #{acceptType}, #{acceptGroupId}, #{outerApplyId,mode=OUT,jdbcType=VARCHAR}</select>
执行效果