- 引入distributedid-client依赖:在项目pom.xml添加坐标
<dependencies> <dependency> <groupId>com.itheima.distributedid</groupId> <artifactId>distributedid-client</artifactId> <version>1.0-SNAPSHOT</version> </dependency></dependencies> - 分布式ID生成系统客户端配置 , 在项目resources目录下编辑distributedid_client.properties
#服务器地址distributedid.server=211.103.136.244:7315#部署多个的话,可自行添加#distributedid.server=211.103.136.244:7315,ip2:port,...#超时时间distributedid.readTimeout=5000distributedid.connectTimeout=5000 - 获取ID时 , 直接调用即可
Long id = 0L;//从服务端获取自增型IDid = DistributedId.autoincrementId("your service name");//本地生成雪花算法IDid = DistributedId.snowflake();//从服务端获取雪花算法IDid = DistributedId.snowflakeFromServer();//使用号段模式获取单个IDid = DistributedId.segment(); - 数据库脚本
/* Navicat Premium Data Transfer Source Server : 本地MySQL数据库 Source Server Type : MySQL Source Server Version : 50728 Source Host : localhost:3306 Source Schema : distributedid Target Server Type : MySQL Target Server Version : 50728 File Encoding : 65001*/SET NAMES utf8mb4;SET FOREIGN_KEY_CHECKS = 0;-- ------------------------------ Table structure for segment_id_info-- ----------------------------DROP TABLE IF EXISTS `segment_id_info`;CREATE TABLE `segment_id_info` ( `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '自增主键', `biz_type` varchar(63) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '业务类型,唯一', `begin_id` bigint(20) NOT NULL DEFAULT 0 COMMENT '开始id,仅记录初始值,无其他含义 。初始化时begin_id和max_id应相同', `max_id` bigint(20) NOT NULL DEFAULT 0 COMMENT '当前最大id', `step` int(11) NULL DEFAULT 0 COMMENT '步长', `delta` int(11) NOT NULL DEFAULT 1 COMMENT '每次id增量', `remainder` int(11) NOT NULL DEFAULT 0 COMMENT '余数', `create_time` timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '创建时间', `update_time` timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '更新时间', `version` bigint(20) NOT NULL DEFAULT 0 COMMENT '版本号', PRIMARY KEY (`id`) USING BTREE, UNIQUE INDEX `uniq_biz_type`(`biz_type`) USING BTREE) ENGINE = InnoDB AUTO_INCREMENT = 6 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '号段ID信息表' ROW_FORMAT = Dynamic;-- ------------------------------ Table structure for sequence_id-- ----------------------------DROP TABLE IF EXISTS `sequence_id`;CREATE TABLE `sequence_id` ( `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '自增主键', `biz_type` char(10) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '业务类型,唯一', PRIMARY KEY (`id`) USING BTREE, UNIQUE INDEX `biz_type`(`biz_type`) USING BTREE) ENGINE = InnoDB AUTO_INCREMENT = 62 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;SET FOREIGN_KEY_CHECKS = 1;推荐阅读
- 第五人格或许可以找鹤翁帮忙怎么做
- Number,String类型 第一百零八篇:最常用的基本数据类型
- 第五人格给鹤翁盛水任务完成攻略
- 第五人格或许可以找鹤翁帮忙位置图示
- -第五人格鹤翁盛水方法攻略
- 第五人格鹤翁位置在哪
- 第五人格试着寻找长明灯怎么完成
- 王者荣耀炮火千金探索第4阶段正确答案参考-王者荣耀炮火千金探索第四阶段答案攻略
- 王者荣耀炮火千金探索第3阶段通关答案攻略-王者荣耀炮火千金探索第三阶段怎么过
- 王者荣耀炮火千金探索第2阶段答案图文攻略-王者荣耀炮火千金探索第二阶段怎么玩