导入maven依赖:
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-core</artifactId>
<version>1.6.0</version>
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-spring</artifactId>
<version>1.6.0</version>
</dependency>
工具类:
import java.io.Serializable;
import org.apache.shiro.session.Session;
import java.security.SecureRandom;
import java.util.UUID;
/**
* @Description:
* @Author nc
* @Date 2021/08/25 20:08
*/
public class IdGen {
private static SecureRandom random = new SecureRandom();
/**
* 封装JDK自带的UUID, 通过Random数字生成, 中间无-分割.
*/
public static String uuid() {
return UUID.randomUUID().toString().replaceAll("-", "");
}
/**
* 使用SecureRandom随机生成Long.
*/
public static long randomLong() {
return Math.abs(random.nextLong());
}
/**
* Activiti ID 生成
*/
public String getNextId() {
return IdGen.uuid();
}
public Serializable generateId(Session session) {
return IdGen.uuid();
}
}
1