![](/img/trans.png)
[英]MyBatis: Attempted to return null from a method with a primitive return type
[英]mybatis return primitive type for procedure call
我想在調用oracle過程后返回原始類型,這是我的mybatis接口:
public interface ProcedureMapper {
int getProcedureResult();
}
我想執行一個過程或函數然后返回狀態,我嘗試了以下配置:
<select id="getProcedureResult" statementType="CALLABLE" resultType="int">
BEGIN
EXECUTE IMMEDIATE 'CREATE TABLE temp_tt (id NUMBER(12) )';
#{status,mode=OUT,jdbcType=INTEGER} := 0;
EXCEPTION
WHEN OTHERS THEN
#{status,mode=OUT,jdbcType=INTEGER} := -1;
END;
</select>
不起作用,將引發異常:
Caused by: org.apache.ibatis.reflection.ReflectionException: Could not set property 'status' of 'class java.lang.Class' with value 'null' Cause: org.apache.ibatis.reflection.ReflectionException: There is no setter for property named 'status' in 'class java.lang.Class'
我知道我可以在里面使用'status'屬性將resultType設置為Java Bean,但是我只想返回原始類型而不是Java Bean,有什么想法嗎?
像這樣在字符串中編寫過程-
public String proc = "BEGIN\n"
+"\tEXECUTE IMMEDIATE 'CREATE TABLE temp_tt (id NUMBER(12) )';\n"
+"\tstatus := 0;\n"
+"\tEXCEPTION\n"
+"\t\tWHEN OTHERS THEN\n"
+"\tstatus := 0;\n"
+"\tEND;\n"
並在您在mybatis中調用該處理器的Java代碼中執行以下語句
session.getConnection().prepareCall(String.format(proc)).execute();
另一個解決方案是:
另一個解決方案是在數據庫中創建您的過程並將其保存。 並從mybatis調用它
<update id="getProcedureResult" statementType="CALLABLE">
{call some_procedure(
#{status, javaType=java.lang.Integer, jdbcType=INTEGER, mode=OUT})
}
</update>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.