實體對象 主鍵IdType要設置為AUTO 表示數據庫ID自增
1
2
3
4
5
6
7
8
9
10
11
12
|
@Data @EqualsAndHashCode (callSuper = false ) @Accessors (chain = true ) public class Employee implements Serializable { private static final long serialVersionUID = 1L; @TableId (value = "id" , type = IdType.AUTO) private Integer id; private String lastName; private String email; private Integer gender; private Integer age; } |
返回的實體就會包含主鍵值
1
2
3
4
5
6
7
8
|
@PostMapping ( "add" ) @ResponseBody public Employee addEmployee() { Employee employee = new Employee(); employeeService.saveOrUpdate(employee); return employee; } |
或者mapper層使用insert方法也會返回主鍵
1
2
3
4
5
|
@Override public Employee saveEmp(Employee employee) { baseMapper.insert(employee); return employee; } |
到此這篇關于MybatisPlus中插入數據后獲取該對象主鍵值的文章就介紹到這了,更多相關MybatisPlus 獲取對象主鍵值內容請搜索服務器之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持服務器之家!
原文鏈接:https://blog.csdn.net/weixin_45631876/article/details/106517711