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

How to solve the problem of Mybatis Plus using @ TableId pit

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly explains "Mybatis Plus use @ TableId pit how to solve", the article explains the content is simple and clear, easy to learn and understand, now please follow the editor's train of thought slowly in depth, together to study and learn "Mybatis Plus use @ TableId pit how to solve it!"

Mybatis Plus uses @ TableID pit 1. TableId optional type

When no comments are added, ID_WORKER (3) is used by default

Public enum IdType {/ * Database ID self-increment * / AUTO (0), / * this type is not set primary key type (will follow the global) * / NONE (1), / * user input ID *

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) * / ID_WORKER (3), / * globally unique ID (UUID) * / UUID (4), / * string globally unique ID (string representation of idWorker) * / ID_WORKER_STR (5);} 2. @ TableId (value = "id", type= IdType.AUTO)

Conditions of use:

The id type can be Interger/Long

The database primary key id,mysql must set the self-incrementing primary key, and postgreSQL must set the self-incrementing sequence to use this annotation.

3. @ TableId (value = "id" type= IdType.ID_WORKER)

Conditions of use:

Id type must be Long

Because the snowflakeId generated by ID_WORKER is a 19-bit global id.

Invalid Mybatis Plus TableId

The initial use of mybatisplus, at first normal, and later found that the insertion is always duplicate key, Pepsi does not understand, and then found that the problem is as follows

@ TableId (type = IdType.ID_WORKER) private Long id; # correct private long id; # error private int id; # error Thank you for your reading, the above is the content of "how to solve the Mybatis Plus using @ TableId pit". After the study of this article, I believe you have a deeper understanding of how to solve this problem with the use of @ TableId pit, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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