我开始学习Mybatis,并且搜索了如何处理存储函数。 我想知道如何用mybatis调用存储函数。 我可以使用这里描述的存储过程http://loianegroner.com/2011/03/ibatis-mybatis-working-with-stored-procedures/如何用mybatis调用存储函数
在此先感谢。
我开始学习Mybatis,并且搜索了如何处理存储函数。 我想知道如何用mybatis调用存储函数。 我可以使用这里描述的存储过程http://loianegroner.com/2011/03/ibatis-mybatis-working-with-stored-procedures/如何用mybatis调用存储函数
在此先感谢。
您可能会将返回值表示为OUT参数。
{ CALL #{retval, mode=OUT, jdbcType=INTEGER} = getResult(#{inval, mode=IN, jdbcType=INTEGER})}
至少这是我在这里找到: http://mybatis-user.963551.n3.nabble.com/How-to-map-function-call-td3457305.html
你的映射文件应该有这样的事情
<update id="myMappedStatement" parameterType="map" statementType="CALLABLE">
{#{returnedVal,javaType=String,jdbcType=VARCHAR,mode=OUT} = call myFunc(
#{myParam1, javaType=String, jdbcType=VARCHAR,
mode=IN},#{myParam2, javaType=String, jdbcType=VARCHAR,
mode=IN},#{myParam3, javaType=String, jdbcType=VARCHAR,
mode=IN})}
</update>
调用函数应该是这个样子:
public String myFunction(Map myParams)
{
//assuming the dao has an Object sqlSessionFactory of type SqlSessionFactory
SqlSession session = sqlSessionFactory.openSession();
try
{
session.update("myMappedStatement",myParams);
//now myParams contains an entry with key "returnedVal"
return (String)myParams.get("returnedVal");
}
catch (Exception ex)
{
}finally {
session.close();
}
}
我使用这个此刻:
<resultMap id="resultBalance" type="Balance">
<result property="balance" column="BALANCE"/>
</resultMap>
<select id="getBalance" parameterType="Registration" resultMap="resultBalance">
select MB_CHECK_BALANCE(#{account} , #{msisdn}) as BALANCE from dual
</select>
为此,您可以使用注释,像这样:
@Select(value = "select function(#{param1}, #{param2}) as returnedValueAlias")
public ReturnedType getFunctionValue(
@Param("param1") Param1Type param1,
@Param("param2") Param2Type param2);
谢谢你,但我尝试过,但它不工作 – 2012-04-10 07:17:37