Home  >  Q&A  >  body text

eclipse - spring mvc + myBatis update不生效

运行环境 linux + tomcat
框架: springMvc + myBatis
数据库:ORACLE

合作方调用我们的一个接口方法,能调用到,我们这边报文接收后 与 他们 进行对比 也是一致的。并且解密后也都能解析出来。
但是执行调用 dao.update方法时,不能成功修改。
而我们本地用client模拟发送一样报文post请求,dao.update方法,数据库能成功修改字段信息

这段是接口方法代码
`@Transactional(readOnly = false)

public Map<String,Object> auditNotice(String loanId ,Integer auditFlag){
     Map<String,Object> msg = new HashMap<String,Object>();
     String errMsg = "更改状态失败";
     TbLoan  tbLoan = null;
     Date date = new Date();
     if(auditFlag == 0){
         //审核通过,更改商户的贷款状态为审核通过
         tbLoan = tbLoanDao.get(loanId);
         if(null != tbLoan){
             System.out.println("贷款状态:"+tbLoan.getLaonStatus());
             if(tbLoan.getLaonStatus().equals(Const.LOAN_STATUS_CONST.DAI_SHEN_HE)){
                 try {
                     TbLoan tbLoan2 = new TbLoan();
                     tbLoan2.setId(loanId);
                     tbLoan2.setUpdateDate(date);
                     User user = new User();
                     user.setId("xiaoyinglicai");
                     tbLoan2.setUpdateBy(user);
                     tbLoan2.setAuditPerson("xiaoying");
                     tbLoan2.setAuditTime(date);
                     tbLoan2.setRemarks("我是remark22");
                     tbLoan2.setLaonStatus(Const.LOAN_STATUS_CONST.SHEN_HE_TONG_GUO);
                     System.out.println("-------------开始更新贷款状态---------");
                     System.out.println("贷款编号:"+loanId);    
                     System.out.println("状态:"+tbLoan2.getLaonStatus());    
                     **int i = tbLoanDao.update(tbLoan2);**
                     if(i < 1){
                         errMsg = "审核结果通知调用失败,状态更改未成功,请重新调用!";
                         msg.put("ret", -1);
                     }else{
                         errMsg = "审核成功";
                         System.out.println(errMsg+"修改条数:"+i);
                         msg.put("ret", 0);
                     }
                 } catch (Exception e) {
                     errMsg = e.getMessage();
                 }
                 
             }else{
                 errMsg = "商户不是待审核状态";
                 msg.put("ret", -1);
             }
         }else{
             errMsg = "未找到相应的商户信息";
             msg.put("ret", -1);
      }
     }else{
         errMsg = "资金方审核未通过";
         msg.put("ret", -1);
         //审核不通过,修改商户贷款状态为不通过(终审)
         TbLoan tbLoan2 = new TbLoan();
         tbLoan2.setId(loanId);
         tbLoan2.setUpdateDate(date);
         User user = new User();
         user.setId("xiaoyinglicai");
         tbLoan2.setUpdateBy(user);
         tbLoan2.setAuditPerson("xiaoying");
         tbLoan2.setAuditTime(date);
         tbLoan2.setRemarks("我是remark_3");
         tbLoan2.setLaonStatus(Const.LOAN_STATUS_CONST.SEHN_HE_SHI_BAI);
         tbLoanDao.update(tbLoan2);
         if(tbAuditFlagService.get(loanId)!=null){                 
             TbAuditFlag tbAuditFlag = new TbAuditFlag();
             tbAuditFlag.setRemarks(errMsg);
             tbAuditFlag.setLoanId(loanId);
             tbAuditFlagService.save(tbAuditFlag);
         }
     }
     msg.put("msg", errMsg);
     String json = JSONUtils.toJSONString(msg);
    System.out.println("审核通知:"+json);
        return msg;
}`

关键代码是 int i = tbLoanDao.update(tbLoan2); 合作方调用与我们本地client调用,这个i都返回1,区别就是数据库有没成功修改。

以下是合作方调用后的日志

-------------开始更新贷款状态---------
贷款编号:22150
状态:2
审核成功修改条数:1
审核通知:{"ret":0,"msg":"审核成功"}

并没有抛异常


求大神给思路!!

高洛峰高洛峰2758 days ago727

reply all(2)I'll reply

  • 怪我咯

    怪我咯2017-04-24 09:12:44

    @Transactional(readOnly = false)

    This comment is inappropriate

    reply
    0
  • 怪我咯

    怪我咯2017-04-24 09:12:44

    1. Transaction rolled back
    2. Classic database problem - lost updates

    reply
    0
  • Cancelreply