使用MyBatis调用oracle函数(基于注释)

时间:2014-11-05 13:56:33

标签: java oracle mybatis ibatis mybatis-generator

我需要使用Annotations在MyBatis中调用Oracle Function。

我的映射器:

@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,mapper的返回值也为null。

任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:2)

创建一个域类SpInOut类

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);