From ffb382ba34aca2dce08ab9e4ef09adc946cf23c8 Mon Sep 17 00:00:00 2001
From: ZY <zc857179121@qq.com>
Date: 星期日, 27 四月 2025 17:26:31 +0800
Subject: [PATCH] 双数据源

---
 src/main/java/com/zy/common/config/ds/DataSourceType.java |   32 ++++++++++++++++++++++++++++++++
 1 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/zy/common/config/ds/DataSourceType.java b/src/main/java/com/zy/common/config/ds/DataSourceType.java
new file mode 100644
index 0000000..d64f307
--- /dev/null
+++ b/src/main/java/com/zy/common/config/ds/DataSourceType.java
@@ -0,0 +1,32 @@
+package com.zy.common.config.ds;
+
+public class DataSourceType {
+
+    public enum DataBaseType {
+        TEST01, TEST02
+    }
+
+    // 浣跨敤ThreadLocal淇濊瘉绾跨▼瀹夊叏
+    private static final ThreadLocal<DataBaseType> TYPE = new ThreadLocal<DataBaseType>();
+
+    // 寰�褰撳墠绾跨▼閲岃缃暟鎹簮绫诲瀷
+    public static void setDataBaseType(DataBaseType dataBaseType) {
+        if (dataBaseType == null) {
+            throw new NullPointerException();
+        }
+        System.err.println("[灏嗗綋鍓嶆暟鎹簮鏀逛负]锛�" + dataBaseType);
+        TYPE.set(dataBaseType);
+    }
+
+    // 鑾峰彇鏁版嵁婧愮被鍨�
+    public static DataBaseType getDataBaseType() {
+        DataBaseType dataBaseType = TYPE.get() == null ? DataBaseType.TEST01 : TYPE.get();
+        System.err.println("[鑾峰彇褰撳墠鏁版嵁婧愮殑绫诲瀷涓篯锛�" + dataBaseType);
+        return dataBaseType;
+    }
+
+    // 娓呯┖鏁版嵁绫诲瀷
+    public static void clearDataBaseType() {
+        TYPE.remove();
+    }
+}

--
Gitblit v1.9.1