Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the global id generation strategy for Mybatis-plus

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Most people do not understand the knowledge of this "Mybatis-plus global id generation strategy" article, so the editor summarizes the following, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "what is the Mybatis-plus global id generation strategy" article.

Mybatis-plus Global id Generation Strategy

After adding the following code to the configuration file, you do not need to add it to the id of the entity class.

@ TableId (value = "id", type = IdType.AUTO) mybatis-plus: global-config: db-config: id-type: auto # set primary key automatic generation strategy (global id generation strategy) Summary of Mybatis-plus6 primary key generation strategy / * database ID self-increment, database needs to support primary key self-increment (such as MySQL) And set the primary key self-increment * / AUTO (0), / * this type is not set primary key type, the default is generated by snowflake algorithm (snowflake) / NONE (1), / * the user enters ID, and the data type is consistent with the database *

This type can be populated by registering the auto-fill plug-in yourself.

* / INPUT (2), / * the following three types are automatically populated only when the insert object ID is empty. * / / * globally unique ID (idWorker). Numeric types must also be numeric types in the database, otherwise error will be reported. * mp comes with a policy to generate 19-bit values. Numeric types use this strategy, such as long * / ID_WORKER (3), / * * globally unique ID (UUID). (no dash) * unique value for each generation * disadvantage: sorting is not convenient * / UUID (4), / * string globally unique ID (string representation of idWorker), database should also ensure the same character type * mp has its own strategy, generate 19-bit value string type using this strategy * / ID_WORKER_STR (5)

Directly annotate the primary key field of the entity class to configure which strategy to use

For example:

@ TableId (type = IdType.ID_WORKER_STR) private String id; above is the content of this article on "what is the global id generation strategy for Mybatis-plus?". I believe you all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to learn more about the relevant knowledge, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report