Get the App
SLTechnology News&Howtos  ›  Servers  › 

How Mybatisplus uses @ EnableKeyGen to start the custom primary key padding function in the startup class

Shulou Source: shulou.com Published: 2022-06-01 00:52:52 10月02日 Update

This article mainly introduces how Mybatisplus uses @ EnableKeyGen to start the primary key to customize the primary key filling function in the startup class, which has a certain reference value, and interested friends can refer to it. I hope you can learn a lot after reading this article.

Use @ EnableKeyGen to start the custom primary key fill function in the startup class. Note that if you implement IKeyGenerator, it will conflict with @ EnableKeyGen.

@ SpringBootApplication@EnableMPP@EnableKeyGenpublic class PlusDemoApplication {public static void main (String [] args) {SpringApplication.run (PlusDemoApplication.class, args);}}

Set @ KeySequence on the entity class to automatically populate the primary key field with complex calculated values when inserting

@ KeySequence ("select lpad (max (seqno) + 3Magne10) from test") @ TableName (value = "test") public class TestEntity {@ TableId (value = "id", type=IdType.INPUT) private Integer id Thank you for reading this article carefully. I hope the article "Mybatisplus how to use @ EnableKeyGen to start custom primary key filling function in startup class" shared by the editor is helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Articles functions complexity value interests at the same time fields entities more friends knowledge editing industry information information channels channels conflicts references learning help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno MySQL NVidia Xiaomi MariaDB