Java method for generating unique primary key UUID (UUID method)

In normal development, if there is no mechanism for the database to automatically generate ID, you can use the UUID provided by java to generate a random unique primary key. When inserting the database, you can directly assign a value to the ID primary key; This UUID method can be called directly in the utils package of Java:

Example:

public static String getUUID(){

UUID uuid=UUID. randomUUID();

String uuidStr=uuid. toString();

return uuidStr;

}

=======Attention=======

The length of UUID random primary key is 36 bits. During database table design, pay attention to allocate sufficient length for UUID storage columns

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>