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