Get the App
SLTechnology News&Howtos  ›  Development  › 

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

Shulou Source: shulou.com Published: 2022-06-02 08:27:19 09月21日 Update

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!

Tags: Type global learning content character string data database condition comment error problem only can pass object that is sequence idea situation plug-in Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Huawei Microsoft vpn Shulou Information