SelectKey查询id

来源:互联网 发布:矢量动画制作软件 编辑:程序博客网 时间:2024/05/17 06:47

保存同时查询id,在user对象中,通过user.geiId取得id
keyProperty查询的主键是实体类的id属性
resultType = int.class是id的类型

三种方法:
@SelectKey(statement = “select LAST_INSERT_ID()”,keyProperty = “id”,before = false,resultType = int.class)
@SelectKey(statement = “select @@IDENTITY”,keyProperty = “id”,before = false,resultType = int.class)
@SelectKey(statement = “select max(id) id from tb_class”,keyProperty = “id”,before = false,resultType = int.class)
@Insert(“insert into tb_class(name) values(#{name}) “)
void save(User user);

原创粉丝点击