1. 程式人生 > >spring boot mybatis 獲取insert 返回id

spring boot mybatis 獲取insert 返回id

@Insert("INSERT INTO hq_admin(username,truename,password,phone,email) VALUES(#{username},#{truename}, #{password}, #{phone}, #{email})")
@SelectKey(statement="select LAST_INSERT_ID()", keyProperty="id", before=false, resultType=int.class)
void insert(admin user);
adminData.insert(admin);
System.out.println("sssss"
+admin.getId());

插入資料後會返回主鍵ID。參考官網http://www.mybatis.org/mybatis-3/zh/java-api.html#directoryStructure