You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
400 B
Java
19 lines
400 B
Java
package com.glxp.api.util;
|
|
|
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
|
public class SnowflakeUtil {
|
|
|
|
/**
|
|
* 获取雪花id
|
|
*/
|
|
public static synchronized Long getId() {
|
|
int workId = RandomUtil.randomInt(0, 31);
|
|
int dataCenterId = RandomUtil.randomInt(0, 31);
|
|
return IdUtil.getSnowflake(workId, dataCenterId).nextId();
|
|
}
|
|
}
|
|
|