Mybaits中session的应用一

        获取一级缓存session
        SqlSession session = this.yangchebaoDbManagerImpl.getSqlSessionFactory().openSession(false)
  MaintainOrderMapper maintainOrderMapper = session.getMapper(MaintainOrderMapper.class);
        MaintainOrderPayMapper maintainOrderPayMapper = session.getMapper(MaintainOrderPayMapper.class);
        try {
            order.setIspay(EnumUUStatusDesc.IS_PAY_ONLINE.getIntegerValue());// 付款状态
            order.setIspayName(EnumUUStatusDesc.IS_PAY_ONLINE.getText());// 支付方式描述
            order.setPayChannelId(payChannelId);
            
            // 订单支付记录
            MaintainOrderPay orderPay = new MaintainOrderPay();
            orderPay.setMaintainOrderId(orderId);// 上门保养订单ID
            orderPay.setPayChannelId(payChannelId);// 支付渠道ID
            orderPay.setTradeNo(tradeNo);// 第三方支付交易号
            orderPay.setRedeemCode(null);// 抵用券/优惠券信息
            orderPay.setPayment(order.getPayment());// 通过该支付渠道支付的金额
            orderPay.setDiscount(0.0);// 抵扣金额
            orderPay.setTradeDate(now);// 交易完成时间
            orderPay.setStatus(SwitchStatus.YES.getCode());// 交易状态  0:失败  1:成功
            orderPay.setCreateDate(now);// 记录创建时间
            
            // 更新订单的相关信息
            maintainOrderMapper.updateByPrimaryKey(order);
            
            // 添加订单支付记录
            maintainOrderPayMapper.insert(orderPay);
            
            session.commit();
            this.loadOnlinePaySuccessOrder(orderId, now);
        } catch (Exception e) {
            session.rollback();
            logger.error(e.getMessage(), e);
            throw new InternalErrorException(e);
        } finally {
            session.close();
        }
原文地址:https://www.cnblogs.com/tian830937/p/5520196.html