From 0d4e00ec9d9376cdbba76a2fa98fe44ab3bc2f5b Mon Sep 17 00:00:00 2001 From: Michael Yang Date: Mon, 11 Mar 2024 16:57:28 +0800 Subject: [PATCH 1/2] doc: update docs --- docs/.vitepress/config.ts | 2 +- docs/zh/faq.md | 9 ++++++--- docs/zh/others/codegen.md | 23 +++++++++++++++-------- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index 6a87a57a..8998ed18 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -30,7 +30,7 @@ export default defineConfig({ {text: '帮助文档', link: '/zh/intro/what-is-mybatisflex'}, {text: '🆘 常见问题', link: '/zh/faq'}, {text: '周边 / 视频教程', link: '/zh/awesome-things'}, - {text: '代码生成器', link: '/zh/others/codegen.md'}, + {text: '🍷代码生成器', link: '/zh/others/codegen.md'}, {text: '更新日志', link: '/zh/changes'}, {text: 'JavaDoc', link: 'https://apidoc.gitee.com/mybatis-flex/mybatis-flex/'}, diff --git a/docs/zh/faq.md b/docs/zh/faq.md index 9412688a..4e96fa7a 100644 --- a/docs/zh/faq.md +++ b/docs/zh/faq.md @@ -204,10 +204,13 @@ spring: ## 代码生成器获取不到注释 -如果是 MySQL 数据库的话,可能是因为数据库版本太低,解决办法:MySQL 5.* 需要在 jdbcUrl 设置参数 `useInformationSchema=true` 才能获取到注释。 +如果是 MySQL 数据库的话,可能是因为数据库版本太低,解决办法:在 jdbcUrl 设置参数 `useInformationSchema=true` 才能获取到注释。 例如:`jdbc:mysql://127.0.0.1:3306/mybatis-flex?characterEncoding=UTF-8&useInformationSchema=true` + +如果是 Oracle, 则需要添加参数 `remarksReporting=true` ,例如:`jdbc:oracle:thin:@localhost:1521:orcl?remarksReporting=true` + ## 与 Nacos 集成时出错,无法正常启动 MyBatis-Flex 一般情况下,是因为缺少 Nacos 的相关 Maven,注意添加如下的 Nacos 依赖: @@ -229,7 +232,7 @@ FlexConfiguration configuration = new FlexConfiguration(); MybatisFlexBootstrap.getInstance().setConfiguration(configuration); ``` -2、在使用 Spring-Boot 的场景下: +2、在使用 SpringBoot 的场景下: ```java @Configuration @@ -243,7 +246,7 @@ public class MyConfigurationCustomizer implements ConfigurationCustomizer { } ``` -3、只使用 Spring(不使用 Spring-Boot ) 的场景: +3、只使用 Spring(不使用 SpringBoot ) 的场景: ```java @Bean diff --git a/docs/zh/others/codegen.md b/docs/zh/others/codegen.md index 00e10011..a9e1978f 100644 --- a/docs/zh/others/codegen.md +++ b/docs/zh/others/codegen.md @@ -1,12 +1,17 @@ # MyBatis-Flex 代码生成器 -在 mybatis-flex 的模块 `mybatis-flex-codegen` 中,提供了可以通过数据库表,生成 Entity 类和 Mapper 类的功能。当我们把数据库表设计完成 -后可以使用其快速生成 Entity、 Mapper、 Service、 Controller 等产物。 除此之外,我们还可以通过扩展生成更多种类的物料。 +## 简介 -在使用前先添加 `mybatis-flex-codegen` 的 Maven 依赖: +在 mybatis-flex 中,有了一个名称为 `mybatis-flex-codegen` 的模块,提供了可以通过数据库表,生成代码的功能。当我们把数据库表设计完成后, +就可以使用其快速生成 Entity、 Mapper、 Service、 Controller 等产物。 + +除此之外,我们还可以通过扩展生成更多的产物,文档参考 [#添加其他产物的生成](#添加其他产物的生成)。 + +## 快速开始 + +在使用之前,我们需要先添加 `mybatis-flex-codegen` 的 Maven 依赖: ```xml - com.mybatis-flex mybatis-flex-codegen @@ -122,7 +127,7 @@ public class Codegen { 关闭 APT 的 Mapper 类文件生成,请参考:[APT 设置章节](../others/apt.md) -## 使用介绍 +## 功能介绍 在 Mybatis-Flex 的代码生成器中,支持如下 8 种类型的的产物生成: @@ -135,6 +140,8 @@ public class Codegen { - MapperXml 文件 - package-info.java 文件 +> 除此之外,我们可以添加扩展生成更多类型的产物,文档参考 [#添加其他产物的生成](#添加其他产物的生成)。 + 启用或关闭某种类型产物的生成,代码如下: ```java @@ -155,7 +162,7 @@ globalConfig.enableEntity() ## 全局配置 `GlobalConfig` -> 可以像先前一样直接使用 `setXxx()` 进行配置,也可以使用 `getXxxConfig().setXxx()` 进行分类配置。 +### 详细配置 | 获取配置 | 描述 | |------------------------|------------------| @@ -233,7 +240,7 @@ globalConfig.getJavadocConfig() ```java globalConfig.getPackageConfig() - .setSourceDir("D://files/java") + .setSourceDir("D:\\files\\java") .setBasePackage("com.your.domain"); ``` @@ -277,7 +284,7 @@ globalConfig.getStrategyConfig() ```java globalConfig.getTemplateConfig() .setTemplate(new FreeMarkerTemplate()) - .setEntity("D:\your-template-file\my-entity.tpl"); + .setEntity("D:\\your-template-file\\my-entity.tpl"); ``` ## Entity 生成配置 `EntityConfig` From e5b84ca993b370e81636171ea34bbf2cad9808ef Mon Sep 17 00:00:00 2001 From: Michael Yang Date: Mon, 11 Mar 2024 21:08:46 +0800 Subject: [PATCH 2/2] feat: Add MapUtil.java to replace mybatis MapUtil --- .../com/mybatisflex/core/util/MapUtil.java | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 mybatis-flex-core/src/main/java/com/mybatisflex/core/util/MapUtil.java diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/MapUtil.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/MapUtil.java new file mode 100644 index 00000000..bb041623 --- /dev/null +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/MapUtil.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.mybatisflex.core.util; + +import java.util.Map; +import java.util.function.Function; + +public class MapUtil { + private static final boolean IS_JDK8 = (8 == getJvmVersion0()); + + private MapUtil() { + } + + private static int getJvmVersion0() { + int jvmVersion = -1; + try { + String javaSpecVer = StringUtil.tryTrim(System.getProperty("java.specification.version")); + if (StringUtil.isNotBlank(javaSpecVer)) { + if (javaSpecVer.startsWith("1.")) { + javaSpecVer = javaSpecVer.substring(2); + } + if (javaSpecVer.indexOf('.') == -1) { + jvmVersion = Integer.parseInt(javaSpecVer); + } + } + } catch (Throwable ignore) { + // ignore + } + // default is jdk8 + if (jvmVersion == -1) { + jvmVersion = 8; + } + return jvmVersion; + } + + /** + * A temporary workaround for Java 8 specific performance issue JDK-8161372 .
+ * This class should be removed once we drop Java 8 support. + * + * @see https://bugs.openjdk.java.net/browse/JDK-8161372 + */ + public static V computeIfAbsent(Map map, K key, Function mappingFunction) { + if (IS_JDK8) { + V value = map.get(key); + if (value != null) { + return value; + } + } + return map.computeIfAbsent(key, mappingFunction); + } + + +}