Mybatis 插入数据后,自动返回其主键值


Vo实体类:

controller 层:

service 层:

serviceImpl 层:

mapper 层:

mapper.xml 文件:

插入数据的主键值其实是赋值给你指定的entity的某个字段中。
核心代码:useGeneratedKeys="true" keyProperty="id"
然后通过实体类.get方法得出主键值。