表的id是自增id,mybatis怎么实现插入数据之后返回自增id?
解决方法:
Controller层
Applyinfo application = new Applyinfo();
application.setName(name);
application.setAdress(adress);
application.setSex(sex);
//插入领用信息表
ApplyinfoServices.insertApplyinfo(info);
//取出id
int incrementId = application.getId();
Dao层
@Insert("INSERT INTO applyinfo (name,address,sex) VALUES (#{name},#{address},#{sex})")
@Options(useGeneratedKeys=true,keyProperty="id",keyColumn="id")
void insertApplyinfo(Applyinfo application);
在插入后,使用application.getId()(对象.主键属性)获取刚刚插进去的主键值。
id为你要插入表的id