有输入与输出参数的存储过程
oracle存储过程部分代码:
create or replace procedure PT_copy_Shipment_One_Data(
oldShipmentId in varchar ,
servprovGid in varchar ,
insertUser in varchar,
resultShipmentId out varchar
)is
newShipmentGid varchar2(50 );
newShipmentXid varchar2(50 );
newShipmentTypeGid varchar2(50 );
begin
--执行的PLSQL体
commit;--提交事物
Exception
When others then
Rollback;
end PT_copy_Shipment_One_Data;
mybatis的Xml配置
注意:虽然有返回值,不需要知道设置返回参数类,详情可看下面java代码例子
<select id= "callCoptShipment" parameterType ="map"
statementType="CALLABLE">
<![CDATA[
{call PT_copy_Shipment_One_Data(
#{oldShipmentId,mode=IN,jdbcType=VARCHAR},
#{servprovGid,mode=IN,jdbcType=VARCHAR},
#{insertUser,mode=IN,jdbcType=VARCHAR},
#{resultShipmentId,mode=OUT,jdbcType=VARCHAR}
)}
]]>
</select >
Dao或者Service代码
Map<String, String> parasMap = new HashMap<String, String>();
parasMap.put("oldShipmentId", para.get( "shipmentId"));
parasMap.put( "servprovGid", para.get("skdw"));//attr12
parasMap.put( "insertUser", Users.getCurrent());
parasMap.put( "resultShipmentId", "" );
//调用存储过程
this.getSqlSessionTemplate().
selectOne("com.otm.app.entity.pojo.ShipmentCost.callCoptShipment",parasMap);
parasMap.put("shipmentId", parasMap.get("resultShipmentId" ));
return parasMap;
如上标红的代码,在mybatis不需要设置返回参数,然后在java当中调用存储过程也不需要接受返回参数,map参数当中会自动有。这是一个奇怪的地方。
交流技术群号:50567913