import java.util.UUID;
/**
* @author lf
* @Description:
* @date 2022/5/5
*/
public class IdUtils {
/**
* 根据字符串生成固定UUID
*
* @param name
*/
public static synchronized String getUUID(String name) {
UUID uuid = UUID.nameUUIDFromBytes(name.getBytes());
String str = uuid.toString();
return str.replace("-", "");
}
public static synchronized String simpleUUID() {
UUID uuid = UUID.randomUUID();
String str = uuid.toString();
return str.replace("-", "");
}
/**
* 随机生成UUID
*/
public static synchronized String getUUID() {
UUID uuid = UUID.randomUUID();
String str = uuid.toString();
String uuidStr = str.replace("-", "");
return uuidStr;
}
public static void main(String[] args) {
System.out.println(getUUID("公示"));
}
}
结果: