實(shí)體對象 主鍵IdType要設(shè)置為AUTO 表示數(shù)據(jù)庫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; } |
返回的實(shí)體就會包含主鍵值
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; } |
到此這篇關(guān)于MybatisPlus中插入數(shù)據(jù)后獲取該對象主鍵值的文章就介紹到這了,更多相關(guān)MybatisPlus 獲取對象主鍵值內(nèi)容請搜索服務(wù)器之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持服務(wù)器之家!
原文鏈接:https://blog.csdn.net/weixin_45631876/article/details/106517711