58 lines
1.2 KiB
Plaintext
58 lines
1.2 KiB
Plaintext
|
|
package com.sercurityControl.proteam.util;
|
||
|
|
|
||
|
|
import java.util.Random;
|
||
|
|
import java.util.UUID;
|
||
|
|
|
||
|
|
public class UUIDHelper {
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 封装JDK自带的UUID, 通过Random数字生成, 中间无-分割.
|
||
|
|
*/
|
||
|
|
public static String get32UUID() {
|
||
|
|
String uuid = UUID.randomUUID().toString().trim().replaceAll("-", "");
|
||
|
|
return uuid;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 封装JDK自带的UUID, 通过Random数字生成, 中间有-分割.
|
||
|
|
*/
|
||
|
|
public static String uuid() {
|
||
|
|
return UUID.randomUUID().toString();
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* 得到纯数字编号
|
||
|
|
* @param length 长度
|
||
|
|
* @return
|
||
|
|
*/
|
||
|
|
public static String number(int length) {
|
||
|
|
StringBuilder str = new StringBuilder();
|
||
|
|
for (int i = 0; i < length; i++) {
|
||
|
|
if (i == 0){
|
||
|
|
str.append(getRandom(49, 57));
|
||
|
|
} else{
|
||
|
|
str.append(getRandom(48, 57));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return str.toString();
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* 根据开始和结束大小得到单一字符
|
||
|
|
* @param begin 开始值
|
||
|
|
* @param end 结束值
|
||
|
|
* @return 单一字符
|
||
|
|
*/
|
||
|
|
private static String getRandom(int begin, int end) {
|
||
|
|
String str = "";
|
||
|
|
Random rd = new Random();
|
||
|
|
int number = 0;
|
||
|
|
while (str.length() == 0) {
|
||
|
|
number = rd.nextInt(end + 1);
|
||
|
|
if (number >= begin && number <= end){
|
||
|
|
str = String.valueOf((char) number);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return str;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|