Mybatis calls oracle stored procedure
Stored Procedures with Input and Output Parameters
Oracle stored procedure part code:
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 body executed
commit;--commit something
Exception
When others then
Rollback;
end PT_copy_Shipment_One_Data;
Xml configuration for mybatis
Note: Although there is a return value, do not need to know the return parameter class, see the java code example below for details.
{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}
)}
]]>
Dao or Service Code
Map parasMap = new HashMap();
parasMap.put("oldShipmentId", para.get( "shipmentId"));
parasMap.put( "servprovGid", para.get("skdw"));//attr12
parasMap.put( "insertUser", Users.getCurrent());
parasMap.put( "resultShipmentId", "" );
//call stored procedure
this.getSqlSessionTemplate().
selectOne("com.otm.app.entity.pojo.ShipmentCost.callCoptShipment",parasMap);
parasMap.put("shipmentId", parasMap.get("resultShipmentId" ));
return parasMap;
For example, if the code is superscript red, there is no need to set the return parameter in mybatis, and then there is no need to accept the return parameter when calling the stored procedure in java. The map parameter will automatically have. This is a strange place.
AC Technical Group No.:50567913