增加摘要函数、UID生成函数
This commit is contained in:
parent
d5946b8a33
commit
027774c545
8
src/main/java/dev/surl/surl/util/CheckSumUtil.kt
Normal file
8
src/main/java/dev/surl/surl/util/CheckSumUtil.kt
Normal file
@ -0,0 +1,8 @@
|
||||
package dev.surl.surl.util
|
||||
|
||||
import org.springframework.util.DigestUtils
|
||||
|
||||
fun md5(str: String): String {
|
||||
val cksum = DigestUtils.md5Digest(str.toByteArray())
|
||||
return cksum.joinToString("") { "%02x".format(it) }
|
||||
}
|
15
src/main/java/dev/surl/surl/util/UIDUtil.kt
Normal file
15
src/main/java/dev/surl/surl/util/UIDUtil.kt
Normal file
@ -0,0 +1,15 @@
|
||||
package dev.surl.surl.util
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom
|
||||
|
||||
private val CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".toCharArray()
|
||||
private const val LENGTH = 16
|
||||
|
||||
fun genSurlUID(): String {
|
||||
return genSurlUID(LENGTH)
|
||||
}
|
||||
|
||||
fun genSurlUID(length: Int): String {
|
||||
val random = ThreadLocalRandom.current()
|
||||
return CharArray(length) { CHARS[random.nextInt(CHARS.size)] }.concatToString()
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
server:
|
||||
port: 18888
|
||||
port: 18888 #服务端口
|
||||
spring:
|
||||
application:
|
||||
name: surl
|
||||
name: surl # 应用名称
|
||||
main:
|
||||
banner-mode: off
|
||||
banner-mode: off # 关闭banner
|
||||
|
18
src/test/java/dev/surl/surl/UtilTests.kt
Normal file
18
src/test/java/dev/surl/surl/UtilTests.kt
Normal file
@ -0,0 +1,18 @@
|
||||
package dev.surl.surl
|
||||
|
||||
import dev.surl.surl.util.genSurlUID
|
||||
import dev.surl.surl.util.md5
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class UtilTests {
|
||||
@Test
|
||||
fun md5Test() {
|
||||
assert(md5("sd") == "6226f7cbe59e99a90b5cef6f94f966fd")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun randomUIDTest() {
|
||||
println(genSurlUID())
|
||||
println(genSurlUID(8))
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user