• 周六. 10 月 12th, 2024

5G编程聚合网

5G时代下一个聚合的编程学习网

热门标签

Mybatis plus ID_ Walker strategy trampling record

King Wang

1 月 3, 2022

Document source ,Mybatis-Plus 2.X:https://baomidou.gitee.io/mybatis-plus-doc/#/quick-start

The latest documents ,Mybatis-Plus 3.X:https://mybatis.plus/guide/

If you don’t want to see the process, you can see the solution at the end .

 

First look at the official introduction :

Officials say the default here is ID_WORKER Strategy

But in the actual test, they always report errors , Can’t produce the corresponding ID, Let’s record the process of solving the problem

 

1. The entity class you just started testing should id The data type is Integer

Error is reported after adding data :

Could not set property ‘id’ of ‘class com.hlt.entity.Login’ with value ‘1202575537856352258’ Cause: java.lang.IllegalArgumentException: argument type mismatch

It means generated id Parameter type mismatch

Look at the Internet and say to change it to long type , Because of the 19 Bit data is out of range for this field , So report a mistake ;

But it needs to be changed to Long Can be used , Use long Will not produce id

Reference source :https://blog.csdn.net/qq_27520051/article/details/103058220

 

2. Entity class id Change the type to Long After that, I still reported a mistake :

Error is reported after adding data again :

com.mysql.jdbc.MysqlDataTruncation: Data truncation: Out of range value for column ‘id’ at row 1

Roughly meaning id The value of is out of range

Reference source :https://blog.csdn.net/itmyhome1990/article/details/79299050

 

This is because the database should id Field type is int, Generated ID Beyond its scope , Change it to bigint:

 

Add again success :

 

summary : The solution is

1. Modify the entity class id The type of field is Long

2. modify the database id The type of field is bigint

 

What we have found is mainly caused by these two problems ID Failed to generate , If there are other reasons, it will be updated later .

发表回复