zoukankan      html  css  js  c++  java
  • Mybatis插入数据后返回主键Id

     1.SQLServer 数据库

      // 下面是SQLServer获取最近一次插入记录的主键值的方式 select @@IDENTITY as id INSERT INTO t_Product_GroupBuyingRule (name ,startDate ,endDate ,days ,ajson ,isReturn ,isCanUseIntegral ,isCanUseRed ,useRedType ,channelType ,freightType ,userId ,status ,isUsed) VALUES ( #{name} , #{startDate} , #{endDate} , #{days} , #{ajson} , #{isReturn} , #{isCanUseIntegral} , #{isCanUseRed} , #{useRedType} , #{channelType} , #{freightType} , #{userId} , #{status} , #{isUsed} );

      接收返回id

      //result 返回的是受影响行数

      Integer result = tProductGroupBuyingRuleDao.insertGroupBuyingRule(tProductGroupBuyingRule);System.out.println("result = " + result);//主键ID必须通过实体类获取 tProductGroupBuyingRule.getId()

      System.out.println("tProductGroupBuyingRule.getId() = " + tProductGroupBuyingRule.getId());

      2.MySql数据库

      // 下面是SQLServer获取最近一次插入记录的主键值的方式 select last_insert_id() INSERT INTO t_Product_GroupBuyingRule (name ,startDate ,endDate ,days ,ajson ,isReturn ,isCanUseIntegral ,isCanUseRed ,useRedType ,channelType ,freightType ,userId ,status ,isUsed) VALUES ( #{name} , #{startDate} , #{endDate} , #{days} , #{ajson} , #{isReturn} , #{isCanUseIntegral} , #{isCanUseRed} , #{useRedType} , #{channelType} , #{freightType} , #{userId} , #{status} , #{isUsed} );

      接收返回id

      //result 返回的是受影响行数

      Integer result = tProductGroupBuyingRuleDao.insertGroupBuyingRule(tProductGroupBuyingRule);System.out.println("result = " + result);//主键ID必须通过实体类获取 tProductGroupBuyingRule.getId()

      System.out.println("tProductGroupBuyingRule.getId() = " + tProductGroupBuyingRule.getId());

  • 相关阅读:
    js怪招(摘录篇)
    猪八戒实习笔记(工具总结)
    2014年最新前端开发面试题(面霸题库)
    经典算法:快排的Javascript版本
    IE的CSS相关的BUG(整理一)
    setTimeout()的返回值
    面试回忆录(三)
    面试回忆录(二)
    读取指定文件夹下的全部文件,可通过正则进行过滤,返回文件路径数组 -- 基于node的一个函数
    Backbone简单示例
  • 原文地址:https://www.cnblogs.com/cxxiao/p/12820856.html
Copyright © 2011-2022 走看看