2014-11-05 537 views
1

我需要使用註解在MyBatis中調用Oracle函數。使用MyBatis調用oracle函數(基於註釋)

我的映射:

@Select("{ CALL #{outParam, jdbcType=NUMERIC, mode=OUT} := ORA_FUNC(" 
    + "#{pNum1, jdbcType=NUMERIC, mode=IN}," 
    + "#{pNum2, jdbcType=NUMERIC, mode=IN}," 
    + "#{pNum3, jdbcType=NUMERIC, mode=IN})}") 
@Options(statementType = StatementType.CALLABLE) 
@ResultType(Integer.class) 
public Integer executeFunction(
    @Param("map") Map<String, Object> carteira); 

我呼籲這個簽名:

Map<String, Object> mapParameters = new HashMap<String, Object>(); 
mapParameters.put("pNum1", carteira.getUnimedCarteira()); 
mapParameters.put("pNum2", carteira.getCodCarteira()); 
mapParameters.put("pNum3", carteira.getDigitoCarteira()); 
mapper.obterRedeBeneficiario(mapParameters); 
return mapParameters.get("outParam").toString(); 

outParam爲null,並且映射器的返回是空過。

任何人都可以幫助我嗎?

+0

你可以參考http://stackoverflow.com/questions/26739636/mybatis-mapping- for-fetching-list-of-custom-record-types-in-oracle/26765161#26765161增加了一個完整的例子 – 2014-11-05 19:11:44

+0

Karthik,這個例子是基於XML的,我嘗試在基於註釋的位類似工作 – mEstrazulas 2014-11-05 23:56:41

+0

你能告訴我們嗎你做了什麼改變? – 2014-11-06 05:13:12

回答

2

創建一個域類分拆類

class SpInOut{ 

    private String outParam; 
    private int pNum1; 
    private int pNum2; 
    private int pNum3; 

    //Getters and setters 

} 

,你可以改變你的maaper如下

@Select("{ #{outParam, jdbcType=NUMERIC, mode=OUT} = CALL ORA_FUNC(" 
    + "#{pNum1, jdbcType=NUMERIC, mode=IN}," 
    + "#{pNum2, jdbcType=NUMERIC, mode=IN}," 
    + "#{pNum3, jdbcType=NUMERIC, mode=IN})}") 
@Options(statementType = StatementType.CALLABLE) 
public void executeFunction(
    SpInOut inOut); 
+0

謝謝@ karthik-prasad,它的工作。我嘗試使用HashMap,也可以使用: '@Select(「{CALL#{map.outParam,jdbcType = NUM​​ERIC,mode = OUT}:= ORA_FUNC(」 +「#{map.pNum1,jdbcType = NUM​​ERIC ,模式= IN},「 +」#{map.pNum2,jdbcType = NUM​​ERIC,mode = IN},「 +」#{map.pNum3,jdbcType = NUM​​ERIC,mode = IN})}「) @Options (statementType = StatementType.CALLABLE) @ResultType(Integer.class) 公共整數Exec​​uteFunction來( @Param( 「映射」)地圖<字符串,對象> carteira);' 由於 – mEstrazulas 2014-11-18 13:43:28