可以用于生成不重复的id
1.mysql自增长
2.代码雪花算法
3.mysql触发器
数据表代码
CREATE TABLE `product` (
`id` VARCHAR(40) NOT NULL ,
`productNum` VARCHAR(50) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
`productName` VARCHAR(50) DEFAULT NULL,
`cityName` VARCHAR(50) DEFAULT NULL,
`DepartureTime` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`productPrice` INT(11) DEFAULT NULL,
`productDesc` VARCHAR(500) DEFAULT NULL,
`productStatus` INT(11) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `product` (`id`,`productNum`)
) ENGINE=INNODB DEFAULT CHARSET=utf8;
触发器代码
sqlyog软件点击中间的按键
DELIMITER $$
CREATE
TRIGGER `ssm`.`product_id` BEFORE INSERT
ON `ssm`.`product`
FOR EACH ROW BEGIN
SET new.id =(SELECT UUID());
END$$
DELIMITER ;
INSERT INTO `product`(`id`,`productNum`,`productName`,`cityName`,`DepartureTime`,`productPrice`,`productDesc`,`productStatus`) VALUES ('12B7ABF2A4C544568B0A7C69F36BF8B7','itcast-003','上海五日游','上海','2019-02-04 00:00:00',1800,'魔都我来了',0),('676C5BD1D35E429A8C2E114939C5685A','itcast-002','北京三日游','北京','2019-02-04 00:00:00',1200,'不错的旅行',1),('9F71F01CB448476DAFB309AA6DF9497F','itcast-001','北京三日游','北京','2019-02-04 00:00:00',1200,'不错的旅行',1);