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

  • 相关阅读:
    用graphviz,pygraphviz快速自动绘图
    python 实现的huffman 编码压缩,解码解压缩
    python 字符串的显示
    PKU acm 1651 multiplication puzzle
    SQL Server中的数据类型详解
    (转) treeview 的设计思路
    将英文的week 转换为中文的 简单的方法
    常用的文件对应的MIME类型:
    客户端传参问题
    绑定数据与截取的另外的一中写法
  • 原文地址:https://www.cnblogs.com/cxxiao/p/12820856.html
Copyright © 2011-2022 走看看