需要在mapp.xml 的insert语句上加上

useGeneratedKeys="true" keyProperty="id"     id是数据库表的id字段名称

image
这样插入数据成功后,id就会set到 实体类中,直接调用get方法即可取到新增数据的id