當前位置:
首頁 >
04 UUID
發(fā)布時間:2025/7/14
48
豆豆
1 什么是UUID
UUID 的目的是讓分布式系統(tǒng)中的所有元素,都能有唯一的辨識資訊,而不需要透過中央控制端來做辨識資訊的指定。
?
2 應用場景
MySQL數(shù)據(jù)庫不能想oracle數(shù)據(jù)庫那樣創(chuàng)建序列,就可以利用UUID動態(tài)生成id
?
3 怎么產(chǎn)生UUID序列
直接利用UUID類的靜態(tài)方法
String id = UUID.randomUUID().toString();
注意:randomUUID的返回值是UUID類型,但是它自身的toString方法可以將其轉(zhuǎn)換成字符串
?
4 產(chǎn)生UUID序列源代碼
1 package cn.xiangxu.testNote.test; 2 3 import java.util.UUID; 4 5 public class Test { 6 public static String createId() { 7 8 /* 9 * 利用UUID類的靜態(tài)方法產(chǎn)生序列id 10 * 注意:randomUUID的返回值是UUID類型,但是它自身的toString方法可以將其轉(zhuǎn)換成字符串 11 */ 12 String id = UUID.randomUUID().toString(); 13 return id; 14 } 15 16 public static void main(String[] args) throws Exception { 17 String id = Test.createId(); 18 System.out.println(id); 19 } 20 21 22 } View Code?
轉(zhuǎn)載于:https://www.cnblogs.com/NeverCtrl-C/p/6940994.html
總結(jié)
- 上一篇: big and little endia
- 下一篇: hdu-1029 Ignatius an