mybatis 插入一條資料返回相應資料ID
<insert id="insertTaxiOrder" parameterType="map" useGeneratedKeys="true" keyProperty="ID" > INSERT INTO tb_TaxiOrderInfo ( UserID, DriverID, StartAddress, EndAddress,PublicTime,StartLongitude,StartLatitude ) VALUES (#{userID}, 0, #{StartAdd}, #{EndAdd}, GETDATE(), #{Longitude}, #{Latitude} )
其中加上 useGeneratedKeys=”true” keyProperty=“ID”
這個意思就是說。 他在插入後, 會自動把插入的資料生成的ID
塞入到你這個 keyProperty 後面設定的 ID 這個引數裡面。
執行之後 你直接取ID 的值就好了。
我這裡接收的 parameterType 是 map。
所以在 之前 map 要有這個 key
如果接收的是 實體類的話, 當然實體類裡面就要定義ID 這個屬性了
相關推薦
Mybatis 插入一條記錄返回主鍵
插入一條記錄返回主鍵 情景:向資料庫中插入一條資料,要求返回插入資料的id 主鍵必須為整型,而且支援自增 需求實現:在儲存完成後執行SELECT LAST_INSERT_ID()即可
mybatis 插入一條資料返回相應資料ID
<insert id="insertTaxiOrder" parameterType="map" useGeneratedKeys="true" keyProperty="ID" > INSERT INTO tb_TaxiOrderInfo ( UserID, D
mybatis 插入一條記錄 參數為map的寫法
map rtu dex obj word pan batch doc span xml: <insert id="insertUser" parameterType="java.util.Map"> insert into
mybatis 新增一條新資料並返回此資料的ID(主鍵)
通常資料庫中表的主鍵是‘自動遞增(mysql)’或’序列(oracle)‘,但插入資料後又要取得些條資料的ID(將ID做為主鍵) 利用Mybatis 的 selectKey來獲得: <!-- 新增部門 返回部門ID --> <insert id="ad
插入一條資料後直接得到這條資料的id
今天遇到一個問題就是,想插入後繼續獲得主鍵然後再次操作! 可能有好幾種方法,今天親自測試使用的一種方法記錄一下,分享給大家! 針對的資料庫是MYSQ 主鍵自增l 以下面這個sql為例 <!-- 插入客戶檔案 --><insert id="insertCustom
mybatis 插入資料返回主鍵id寫法
1、batis檔案中寫法: <!--插入資料,返回主鍵的insert寫法 --> <insert id="insert_A" parameterType="Map" useGeneratedKeys="t
(六)Mybatis插入資料返回主鍵id
整個demo放在Github上,地址:【https://github.com/Damaer/Mybatis-Learning】,專案是mybatis-05-CRUD,下載下來只需要maven環境以及mysql環境就可以跑起來,所以不貼全部程式碼。 我們知道很多時候我們有
oracle寫一個先插入一條資料,在將該資料中一個欄位更新的觸發器的坑
最近剛用使用觸發器,原理上應該是在插入之後再更新,原本以為是以下這種寫法,在網上也找了很多方法,結果說的都不太對.需要更新的欄位根本沒有被更新,我想應該是邏輯上的問題: create or replace trigger UPDATE_REDLIST_TYPE afte
java 連帶操作(兩張表關聯,一張表插入一條新資料,另外一張表也跟著插入一條新資料)
以角色許可權模組中增加功能為例子:a) 概念: 連帶操作:首先先在Role表中插入一條資料,接著拿到rid,往Role-Acl表中插入一條資料b)資料庫設計:Role表:Role-Acl表:c) 程式碼實現:RoleMap:/** * * @Description: 新增
mybatis插入多條資料,id自動為生成的uuid,傳入的資料格式為map的解決方式
擼程式碼遇到過這種情況: insert into user(id,user_name,user_age) values (自動生成的uuid,"張三",18), (自動生成的uuid,"李四",19), (自動生成的uuid,"王五",20), (自動生成的uuid,"馮六",21) 使
mybatis 實現插入一條記錄的同時,並返回主鍵自增策略是自增生成的主鍵ID
<insert id="insert" parameterType="com.mmall.pojo.Shipping" useGeneratedKeys="true" keyProperty="id"> insert into mmall_shipping
向Oracle資料庫插入一條資料
這幾天搞了一下Oracle資料庫,可能用sql server習慣了,感覺好不方便。PL的介面友好度比sql server差遠了 ,既然都收購了PL了 為什麼不給它做好一點呢?各種不便。鬱悶 向Oracle伺服器插入一條資料 --不管什麼格式通通用''引號引起來。不過INTE
Java+MySQL:插入一條資料並刪除上一條
大致過程:1.向資料庫中插入一條資料,並獲取新增資料的id-currentId2.找到id為 (currentId-1) 的資料,如果存在則將它刪除,如果不存在繼續將id減一,知道能夠刪除一條資料package jdbc; import java.sql.Connectio
PHP PDO插入一條資料,重複出現兩條的情況
$dsn = sprintf("mysql:host=%s;dbname=%s;charset=utf8", $host, $dbName);$_dbHandle = new PDO
sqlserver觸發器:若插入的事實值超過預警值則向預警表中插入一條預警資料
--建立insert插入型別觸發器 create trigger tgr_data_insert on DATA_RECORD_HISTORY for insert --插入觸發 as --定義變數 declare @tempValue int;
MySql資料庫插入一條資料時,create_time欄位自動新增為當前時間
有時候我們會有這樣的需求。往資料庫新增一條資料。然後表中有一個欄位是creat_time。新增資料的同時,這個欄位預設為當前時間。其實很簡單。設定欄位型別為timestamp。然後下面預設值填寫CURRENT_TIMESTAMP 下面那個根據當前時間戳更新 勾上。yes.搞定
mysql一次插入多條demo測試用資料
1.傻傻的insertINSERT INTO raw_materials.common_picture_setting (PICTURE_SETTING_NAME,PICTURE_SETTING_URL
easyui combobox插入一條資料到選項中
1.combobox通過url遠端載入資料 ,需要在選項的第一條插入一個"-請選擇-" 2.不要再後臺獲取資料時新增 ,要在前臺js中實現 思路: combobox裡面有一個loadFilter回撥函式,這個函式就是過濾後臺返回的資料並顯示,那麼那就可以獲取到後臺返回的資
如何學習大資料?首先你需要一條這樣的大資料學習路線
最近很多人問我現在學習大資料這麼多,他們都是如何學習的呢。很多初學者在萌生向大資料方向發展的想法之後,不免產生一些疑問,應該怎樣入門?應該學習哪些技術?學習路線又是什麼?今天小編特意為大家整理了一份大資料從入門到精通的學習路線。並且附帶學習資料和視訊。希望能夠幫助到大家。 第一階段:Lin
插入一條id自增記錄返回自增後的id
<insert id="insert"> INSERT INTO opr ( ) VALUES (