2012-03-28 111 views

回答

3

你的映射文件應該有這樣的事情

<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(); 
    } 
} 
+0

謝謝你,但我嘗試過,但它不工作 – 2012-04-10 07:17:37

1

我使用這個此刻:

<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> 
1

爲此,您可以使用註釋,像這樣:

@Select(value = "select function(#{param1}, #{param2}) as returnedValueAlias") 
public ReturnedType getFunctionValue(
        @Param("param1") Param1Type param1, 
        @Param("param2") Param2Type param2);