1、存储过程
假设存储过程名称为:p_statisticvalue,
输入参数为整数:a,
输出参数为整数:b
则调用存储过程的一般格式如下:
{call p_statisticvalue(
#{a,mode = IN,jdbcType=java.lang.Integer},
#{b,mode=OUT,jdbcType=java.lang.Integer})
}
在如上格式中,IN表示输入参数,OUT表示输出参数,jdbcType传输入输出参数对应的类型,具体什么类型可以根据存储过程返回值来定。
2、存储函数
假设存储函数名为:nexternal,
输入参数整数:a
则调用存储函数的过程为:
nexternal(#{a})
以上分别定义了存储过程、存储函数的一般格式,那么在mybatis中是怎么调用呢?
<select id="selectId" parameterType = "java.lang.Integer" resultType = "java.lang.Integer" statementType = "CALLABLE">
{
call p_statisticvalue(
#{a,mode = IN,jdbcType=java.lang.Integer},
#{b,mode = OUT,jdbcType=java.lang.Integer})
}
</select>
<select id = "selectName" parameterType = "java.lang.Integer" resultType = "java.lang.String">
select nexternal(#{a})
</select>
注意:调用存储过程中,statementType = "CALLABLE"的配置是必不可少的,有该属性,才能调用存储过程。
扩展:Mybatis支持STATEMENT、PREPARED、或CALLABLE的映射类型,分别支持statement,preparedstatement,callablestatement类型,默认是statementType = "PREPARED"
待更新中。。。。。。。。。。。。。。。。。
更多推荐
Mybatis调用存储过程/存储函数
发布评论