You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 851 B

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
12345678910111213141516171819202122232425262728293031323334
  1. ## 运行环境
  2. JDK 1.8+
  3. ## 引用 maven 包
  4. ```
  5. <dependency>
  6. <groupId>com.github.yitter</groupId>
  7. <artifactId>yitter-idgenerator</artifactId>
  8. <version>1.0.5</version>
  9. </dependency>
  10. ```
  11. ## 调用示例
  12. ```
  13. // 全局初始化设置WorkerId,默认最大2^16-1,可通过调整 WorkerIdBitLength 增加最大值
  14. IdGeneratorOptions options = new IdGeneratorOptions();
  15. options.WorkerId = 1;
  16. YitIdHelper.setIdGenerator(options);
  17. // 以上初始化过程全局只需一次,且必须最先设置
  18. // 初始化以后,即可在需要生成ID的地方,调用以下方法。
  19. long newId = YitIdHelper.nextId();
  20. ```
  21. 如果基于DI框架集成,可以参考 YitIdHelper 去管理 IdGenerator 对象,须使用**单例**模式。
  22. ## options 默认值及说明
  23. 参考源码:/contract/IdGeneratorOptions.java

雪花算法中非常好用的数字ID生成器