From 5c95024062bc8dcb3dd1cd246c7e5f532c1603c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=80=E6=BA=90=E6=B5=B7=E5=93=A5?= Date: Thu, 3 Aug 2023 10:43:24 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20"=E6=9C=AA?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E4=BA=8B=E5=8A=A1=E7=94=9F=E6=88=90=E5=99=A8?= =?UTF-8?q?"=20=E6=97=B6=E7=9A=84=E5=BC=82=E5=B8=B8=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E5=9B=BD=E9=99=85=E5=8C=96=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/exception/locale/LocalizedFormats.java | 2 ++ .../com/mybatisflex/core/keygen/KeyGeneratorFactory.java | 8 +++++++- .../core/exception/locale/LocalizedFormats_zh.properties | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/exception/locale/LocalizedFormats.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/exception/locale/LocalizedFormats.java index e3848311..9c05fc4a 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/exception/locale/LocalizedFormats.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/exception/locale/LocalizedFormats.java @@ -50,6 +50,8 @@ public enum LocalizedFormats implements Localizable { ENTITY_VERSION_NULL("The version value of entity \"{0}\" must not be null."), + + KEY_GENERATOR_BLANK("The name of key generator must not be null or blank."), ; private final String sourceFormat; diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/KeyGeneratorFactory.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/KeyGeneratorFactory.java index f79354e9..673801b4 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/KeyGeneratorFactory.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/KeyGeneratorFactory.java @@ -15,9 +15,12 @@ */ package com.mybatisflex.core.keygen; +import com.mybatisflex.core.exception.FlexExceptions; +import com.mybatisflex.core.exception.locale.LocalizedFormats; import com.mybatisflex.core.keygen.impl.FlexIDKeyGenerator; import com.mybatisflex.core.keygen.impl.SnowFlakeIDKeyGenerator; import com.mybatisflex.core.keygen.impl.UUIDKeyGenerator; +import com.mybatisflex.core.util.StringUtil; import java.util.HashMap; import java.util.Map; @@ -43,9 +46,12 @@ public class KeyGeneratorFactory { * 获取 主键生成器 * * @param name - * @return + * @return 主键生成器 */ public static IKeyGenerator getKeyGenerator(String name) { + if (StringUtil.isBlank(name)){ + throw FlexExceptions.wrap(LocalizedFormats.KEY_GENERATOR_BLANK); + } return KEY_GENERATOR_MAP.get(name.trim()); } diff --git a/mybatis-flex-core/src/main/resources/assets/com/mybatisflex/core/exception/locale/LocalizedFormats_zh.properties b/mybatis-flex-core/src/main/resources/assets/com/mybatisflex/core/exception/locale/LocalizedFormats_zh.properties index 5ac56e73..65c7d023 100644 --- a/mybatis-flex-core/src/main/resources/assets/com/mybatisflex/core/exception/locale/LocalizedFormats_zh.properties +++ b/mybatis-flex-core/src/main/resources/assets/com/mybatisflex/core/exception/locale/LocalizedFormats_zh.properties @@ -12,3 +12,5 @@ UPDATE_ONLY_SUPPORT_1_TABLE=\"UpdateByQuery\" \u4ec5\u652f\u6301\u4f20\u5165 1 \ UPDATE_OR_DELETE_NOT_ALLOW=\u6267\u884c "update" \u6216\u8005 "delete" \u7684 SQL \u65f6\uff0c\u4e0d\u5141\u8bb8\u5168\u8868\u64cd\u4f5c\uff0c\u5fc5\u987b\u8981\u6709 where \u6761\u4ef6\u3002 ENTITY_VERSION_NULL=\u4e50\u89c2\u9501\u5b9e\u4f53\u7c7b\u5fc5\u987b\u8bbe\u7f6e version \u7684\u503c\uff1a{0}\u3002 + +KEY_GENERATOR_BLANK=\u4e3b\u952e\u751f\u6210\u5668\u7684\u540d\u79f0\u4e0d\u80fd\u4e3a null \u6216\u8005\u7a7a\u5b57\u7b26\u4e32\u3002