1
0
mirror of synced 2025-12-25 06:27:58 +08:00
Files
SnowFlake-IdGenerator/Java/README.md
2021-03-30 11:49:05 +08:00

35 lines
734 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
## 运行环境
JDK 1.8+
## 引用 maven 包
```
<dependency>
<groupId>com.github.yitter</groupId>
<artifactId>yitter-idgenerator</artifactId>
<version>1.0.3</version>
</dependency>
```
## 调用示例
```
// 全局初始化设置WorkerId默认最大2^16-1可通过调整 WorkerIdBitLength 增加最大值
IdGeneratorOptions options = new IdGeneratorOptions();
options.WorkerId = 1;
YitIdHelper.setIdGenerator(options);
// 以上初始化过程全局只需一次,且必须最先设置
// 初始化以后即可在需要生成ID的地方调用以下方法。
long newId = YitIdHelper.nextId();
```
如果基于DI框架集成可以参考 YitIdHelper 去管理 IdGenerator 对象,须使用**单例**模式。
## options 默认值及说明
参考源码:/contract/IdGeneratorOptions.java