在mapper.xml里SQL语句里添加keyProperty 和 useGeneratedKeys属性,如:keyProperty="id" useGeneratedKeys="true"。 这样就可获得刚添加的行数据的自增字段的值了。