MybatisPlus中插入数据获取主键值
生活随笔
收集整理的這篇文章主要介紹了
MybatisPlus中插入数据获取主键值
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
場景
項目搭建專欄:
https://blog.csdn.net/BADAO_LIUMANG_QIZHI/column/info/37194
基礎搭建:
https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/89407994
實現
編寫單元測試方法
/**** 測試插入數據獲取主鍵*/@Testpublic void testInsertReturnId() {Employee employee = new Employee();employee.setName("霸道獲取主鍵");employee.setAge(23);employee.setEmail("123@163.com");employee.setGender(1);int result = employeeMapper.insert(employee);System.out.println("************************"+result);Integer id = employee.getId();System.out.println("*********************"+id);}主鍵id設置為自增,在插入數據時沒有對其賦值,要想獲取插入后的
數據的主鍵id值,可以直接在插入后通過Integer id = employee.getId();獲取。
運行測試
查看數據庫
源碼下載
https://download.csdn.net/download/badao_liumang_qizhi/11131709
總結
以上是生活随笔為你收集整理的MybatisPlus中插入数据获取主键值的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MybatisPlus中@TableFi
- 下一篇: MybatisPlus中insert方法