Ibatis调用Oracle存储过程

时间:2022-12-22 15:48:35

存储过程:

procedure proc_pos_check(p_gtin        in varchar2,
p_safe_code in varchar2,
p_in_sell_id in varchar2,
p_buy_id in varchar2,
p_oper_type in varchar2,
p_out_sell_id out varchar2,
p_result out varchar2)


Ibatis配置文件: 

<sqlMap namespace="webservice_procheck">

<parameterMap id="pro_check_req" class="java.util.HashMap">
<parameter property="p_gtin" javaType="java.lang.String" jdbcType="VARCHAR" mode="IN"/>
<parameter property="p_safe_code" javaType="java.lang.String" jdbcType="VARCHAR" mode="IN"/>
<parameter property="p_in_sell_id" javaType="java.lang.String" jdbcType="VARCHAR" mode="IN"/>
<parameter property="p_buy_id" javaType="java.lang.String" jdbcType="VARCHAR" mode="IN"/>
<parameter property="p_oper_type" javaType="java.lang.String" jdbcType="VARCHAR" mode="IN"/>
<parameter property="p_out_sell_id" javaType="java.lang.String" jdbcType="VARCHAR" mode="OUT" />
<parameter property="p_result" javaType="java.lang.String" jdbcType="VARCHAR" mode="OUT" />
</parameterMap>
<procedure id="proCheck" parameterMap="pro_check_req">
{call pkg_pos.proc_pos_check(?,?,?,?,?,?,?)}
</procedure>
</sqlMap>

JavaCode:

   public ProCheckQueryRsp proCheck(ProCheckQueryReq proCheckQueryReq)
{
ProCheckQueryRsp rsp = new ProCheckQueryRsp();
Map<String, String> map = new HashMap<String, String>();

//拼装存储过程 IN 参数
map.put("p_gtin", proCheckQueryReq.getGtin());
map.put("p_safe_code", proCheckQueryReq.getSecurityCode());
map.put("p_in_sell_id", proCheckQueryReq.getSellerID());
map.put("p_buy_id", proCheckQueryReq.getBuyerID());
map.put("p_oper_type", proCheckQueryReq.getOperType());

//拼装存储过程 OUT 参数
map.put("p_out_sell_id", "");
map.put("p_result", "");

//调用存储过程
dbOperation.queryForObject("webservice_procheck.proCheck", map);

//将OUT值存入实体类中
rsp.setSellerID(map.get("p_out_sell_id"));
rsp.setResult(map.get("p_result"));
return rsp;
}