Pārlūkot izejas kodu

mybatis-plus 自定义id生成策略

skyline 2 gadi atpakaļ
vecāks
revīzija
72c04329e1

+ 26 - 0
common/src/main/java/com/kym/common/config/CustomIdGenerator.java

@@ -0,0 +1,26 @@
+package com.kym.common.config;
+
+import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
+import com.kym.common.utils.IDGenerator;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author skyline
+ * @description 数据库自定义ID生成
+ * @date 2023-08-12 15:28
+ */
+@Component
+public class CustomIdGenerator implements IdentifierGenerator {
+
+    private IDGenerator idGenerator;
+
+    public CustomIdGenerator() {
+        this.idGenerator = new IDGenerator(0, 0);
+    }
+
+    @Override
+    public Long nextId(Object entity) {
+        final long id = idGenerator.nextId();
+        return id;
+    }
+}