用sql形式插入数据并获得插入Id,可以用以下方式实现,如何解决并发问题呢?插入时用事务还是?
Sql sql = Sqls.create("insert into User(Name) values(@name)");
sql.setParam("name","张三");
adSpaceDAO.execute(sql);
System.out.println(adSpaceDAO.getMaxId(Test.class));
Sql sql = Sqls.create("insert into User(Name) values(@name)");
sql.setParam("name","张三");
Sql sql2 = Sqls.fetchInt("select max(id) from User");
adSpaceDAO.execute(sql, sql2); // 会是同一个事务内
int id = sql2.getInteger();
@wendal 谢谢
@lmm1990 保险起见, 用Trans包起来确保是一个事务吧