在 MyBatis 中,可以通过在映射文件中使用

xml
insert into user (name, age) values (#{name}, #{age})
这样,在执行 insertUser 操作后,id 属性会被设置为数据库返回的自增主键值。需要注意的是,这种方法只适用于支持自增主键的数据库,例如 MySQL 和 Oracle。
我们项目组正好用到了这个,SEQ_ZONE为sequence,则mybatis配置文件如下: SELECT SEQ_ZONE.CURRVAL AS id from dual insert into TBL_ZONE (ID, NAME ) values (SEQ_ZONE.NEXTVAL, #{name,jdbcType=VARCHAR} )
我觉得你应该在for循环里执行$this->db->insert(),然后用$this->db->insert_id()获取每一次插入后的id
我觉得你应该在for循环里执行$this->db->insert(),然后用$this->db->insert_id()获取每一次插入后的id
到此,以上就是小编对于mybatis如何获取自动生成的主键的问题就介绍到这了,希望这3点解答对大家有用。