简简单单,一行代码搞定:
val uuid = UUID.randomUUID().toString().replace("-", “”)
如果在Java中也可以用
UUID.randomUUID().toString().replaceAll("-", “”)
import org.junit.jupiter.api.Test import org.springframework.boot.test.context.SpringBootTest import java.util.* @SpringBootTest class MockServiceApplicationTests { @Test fun contextUUID() { val uuid = UUID.randomUUID().toString().replace("-", "") println(uuid) } }