From 062723a69c30ff745abd669fc4ed3b6d44badcfe Mon Sep 17 00:00:00 2001 From: norkts Date: Sun, 13 Aug 2023 01:53:24 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E5=A4=8DMybatisKeyGeneratorUtil?= =?UTF-8?q?=E7=B1=BB=E7=9A=84=E7=A9=BA=E6=8C=87=E9=92=88=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=202.=E4=BF=AE=E5=A4=8DMapperInvocationHandler=E7=9A=84?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=B1=BB=E5=9E=8B=E5=BC=BA=E8=BD=AC=E5=BC=82?= =?UTF-8?q?=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mybatisflex/core/keygen/MybatisKeyGeneratorUtil.java | 6 ++++++ .../core/mybatis/MapperInvocationHandler.java | 9 +++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/MybatisKeyGeneratorUtil.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/MybatisKeyGeneratorUtil.java index b165c25c..f258461a 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/MybatisKeyGeneratorUtil.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/keygen/MybatisKeyGeneratorUtil.java @@ -56,6 +56,12 @@ public class MybatisKeyGeneratorUtil { public static KeyGenerator createIdKeyGenerator(TableInfo tableInfo, MappedStatement ms, IdInfo idInfo) { + FlexGlobalConfig flexGlobalConfig = FlexGlobalConfig.getConfig(ms.getConfiguration()); + + if(flexGlobalConfig == null){ + return NoKeyGenerator.INSTANCE; + } + FlexGlobalConfig.KeyConfig globalKeyConfig = FlexGlobalConfig.getConfig(ms.getConfiguration()).getKeyConfig(); KeyType keyType = getKeyType(idInfo, globalKeyConfig); diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/MapperInvocationHandler.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/MapperInvocationHandler.java index a4365639..e52d4256 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/MapperInvocationHandler.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/MapperInvocationHandler.java @@ -41,7 +41,12 @@ public class MapperInvocationHandler implements InvocationHandler { public MapperInvocationHandler(Object mapper, DataSource dataSource) { this.mapper = mapper; - this.dataSource = (FlexDataSource) dataSource; + if(dataSource instanceof FlexDataSource){ + this.dataSource = (FlexDataSource) dataSource; + }else{ + this.dataSource = null; + } + } @@ -65,7 +70,7 @@ public class MapperInvocationHandler implements InvocationHandler { //优先获取用户自己配置的 dbType DbType dbType = DialectFactory.getHintDbType(); if (dbType == null) { - if (dataSourceKey != null) { + if (dataSourceKey != null && dataSource != null) { dbType = dataSource.getDbType(dataSourceKey); } if (dbType == null) {