mybatis调用sqlserver存储过程

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

猜你喜欢

转载自www.cnblogs.com/icanner/p/9585864.html