ALTER TABLE `user` ADD `gmv` decimal(20,6) NOT NULL DEFAULT '0.000000' COMMENT '销售金额' after `count`,
ADD `count` decimal(20,6) NOT NULL DEFAULT '0.000000' COMMENT '销售量' after `gmv`;
ALTER TABLE user ALTER COLUMN name SET DEFAULT '';
alter table user modify column name varchar(510) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '名称';
update user set age = 1 , money = 50.0 where id = 1;
ALTER TABLE user DROP COLUMN `name`;
alter table `user` modify column `age` int(11) NOT NULL COMMENT '年龄',
modify column `iphone` bigint(20) NOT NULL DEFAULT '0' COMMENT '手机号',
add `extra` json DEFAULT NULL COMMENT '额外字段';
ALTER TABLE user ADD index idx_name (`name`) COMMENT '名称索引';
创建:
alter table user add unique index `uniq_name_age` (`name`,`age`) COMMENT 'xxx唯一键';
删除:
ALTER TABLE user DROP INDEX `uniq_name_age`;
CREATE TABLE sku_detail (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
`sku_id` int NOT NULL COMMENT 'SKUID',
`sku_temperature_zone` tinyint(4) DEFAULT '0' COMMENT 'Sku温层:0未知,1冷冻,2冷藏,5常温,7高温',
`sku_name` varchar(128) NOT NULL DEFAULT '' COMMENT 'SKUNAME',
`ctime` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`utime` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`create_by` varchar(64) NOT NULL COMMENT '创建人',
`change_by` varchar(64) NOT NULL DEFAULT '' COMMENT '更新人,默认值为空字符串',
`valid` tinyint(1) NOT NULL DEFAULT 1 COMMENT '是否有效,0:无效,1:有效',
PRIMARY KEY (`id`),
KEY `sku_id` (`sku_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='sku_detail表';
alter table `user` add `extra` json DEFAULT NULL COMMENT 'json字符串';
对应DO或PO属性
private String extra;
集合转为json字符串
userDO.setExtra(GsonUtils.toJsonString(Long类型的集合));
其中GsonUtils参考GsonUtils内容
json字符串转为List集合
List extraList = GsonUtils.fromJson(jsonStr, new TypeToken>() {}.getType());
private Map<Long, Map<String, Long>> map = 你后端的内容;
String json = GsonUtil.toJson(map);
userDO.setExtra(json);
Map<String,Long> json2Map = changeJsonString2Map(userDO.getExtra());
private Map<String, Long> changeJsonString2Map(String str) {
if (StringUtils.isBlank(str)){
return Collections.emptyMap();
}
return new Gson().fromJson(str,new TypeToken<HashMap<String,Long>>(){}.getType());
}