sqlserver中存储过程函数为:
ALTER PROCEDURE [dbo].[egl_point_ship]
@order_id varchar(32),
@b_Success int OUTPUT,
@c_errmsg varchar(250) OUTPUT
...
order_id是传入的值,b_Success和c_errmsg是执行完存储过程后返回输出的值
DAO接口与mapper文件如下:
// mapper接口
void eglPointShip(Map map);
// mapper.xml文件
<update id="eglPointShip" parameterType="map" statementType="CALLABLE">
{
call egl_point_ship(
#{order_id,mode=IN,jdbcType=VARCHAR},
#{b_Success,mode=OUT,jdbcType=INTEGER},
#{c_errmsg,mode=OUT,jdbcType=VARCHAR}
)
}
</update>
server层调用dao接口:
@Transactional
public ProcedureDto pointSend(String moveOrderId) {
Map<String, String> map = new HashMap<>();
map.put(Procedure.orderId, moveOrderId);
// 调用存储过程
this.moveOrdersMapper.eglPointShip(map);
// map里得到返回信息
String bSuccess = String.valueOf(map.get(Procedure.bSuccess));
String cErrmsg = map.get(Procedure.cErrmsg);
if ("0".equals(bSuccess)) {
throw new ApplicationException(cErrmsg);
}
}
2018/9/7修改:存储过程不传map,传对象也是可以的,并且更加清晰
service层方法如下:
public void pointSend(String moveOrderId) {
PointProcedure pointProcedure = new PointProcedure();
pointProcedure.setOrderId(moveOrderId);
// 调用存储过程
this.moveOrdersMapper.eglPointShip(pointProcedure);
// 回调信息
if (0 == pointProcedure.getSuccess()) {
throw new ApplicationException(pointProcedure.getMsg());
}
}
mapper文件里的parameterType需改为传入的对象,也可以删掉不写,mybatis也能够找到该参数