2014-11-05 543 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