Home >Database >Mysql Tutorial >mybatis数据表(mysql)的主键非自增长,如何插入数据(需插入主键)实现主键自增长?

mybatis数据表(mysql)的主键非自增长,如何插入数据(需插入主键)实现主键自增长?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-06 09:33:141899browse

mysqlmybatis数据

举例来说就是有表person,person有id(mysql数据库,主键,非自增),和name,pswd三个字段。如果是自增的情况,我们通常是这样处理

insert into person(name,pswd) values(#{name},#{pswd})

这种情况不许要插入主键,因为person表主键是自增长的。但如果主键不是增长的情况呢?如何处理。主键不是自增长就应该必须插入主键。
在步改动表结构的情况下!我能想到有两种方式可以解决,一个就是插入主键时实现自增长,比如第一次主键插1,第二次插2.这种方式不是很好。第二中就是在mapper.xml中是否可以实现向oracle序列那样进行自增长,小弟能力不够,还希望各位前辈能多多指教。如有更好的方法请指出。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn