0
点赞
收藏
分享

微信扫一扫

UUid手动处理

深夜瞎琢磨 2022-02-26 阅读 34
package com.xiaobai.minio.util;

import cn.hutool.core.util.IdUtil;

import java.io.Serializable;


/**
 * @author yangdaji
 *
 */

/**
 * @author yangdaji
 * @version 1.0
 * @Description: uuid8位
 * @date 22-2-25 下午 10:49
 */
public class UuidUtils implements Serializable {


    private static final String[] strings = {
            "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
            "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o",
            "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
            "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O",
            "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"
    };

    /**
     * 生成随机uuid,简化横线
     *
     * @return
     */
    public static String getUuid() {
        return IdUtil.fastSimpleUUID();
    }


    /**
     * 生成 8位不重复id,性能优于32位id
     *
     * @return
     */
    public static String getShortUuid() {
        StringBuffer stringBuffer = new StringBuffer();
        String uuid = IdUtil.fastSimpleUUID();
        for (int i = 0; i < 8; i++) {
            String substring = uuid.substring(i * 4, i * 4 + 4);
            int x = Integer.parseInt(substring, 16);
            stringBuffer.append(strings[x % 0x3E]);
        }
        return stringBuffer.toString();
    }
}

  • 以上就是手动处理的一个简单uuid生成工具了
举报

相关推荐

0 条评论