ID值是从哪里得到的?
CREATE TABLE user (
id BIGINT(20) PRIMARY KEY NOT NULL COMMENT '主键',
name VARCHAR(30) DEFAULT NULL COMMENT '姓名',
age INT(11) DEFAULT NULL COMMENT '年龄',
email VARCHAR(50) DEFAULT NULL COMMENT '邮箱',
manager_id BIGINT(20) DEFAULT NULL COMMENT '直属上级id',
create_time DATETIME DEFAULT NULL COMMENT '创建时间',
CONSTRAINT manager_fk FOREIGN KEY (manager_id)
REFERENCES user (id)
) ENGINE=INNODB CHARSET=UTF8;
老师,有个疑问,在定义表结构时没有指定id为自增长,当执行
@Test public void insert() { User user = new User(); user.setName("张三"); user.setAge(20); user.setManagerId(1088248166370832385L); user.setCreateTime(LocalDateTime.now()); int rows = userMapper.insert(user); System.out.println("影响记录数:" + rows); }
执行插入数据代码后,1134646077845229570这个id值是从哪里来的?
DEBUG==> Preparing: INSERT INTO user ( id, name, age, manager_id, create_time ) VALUES ( ?, ?, ?, ?, ? )
DEBUG==> Parameters: 1134646077845229570(Long), 张三(String), 20(Integer), 1088248166370832385(Long), 2019-06-01 10:21:20.15(Timestamp)
DEBUG<== Updates: 1
影响记录数:1