Merge remote-tracking branch 'origin/main'

This commit is contained in:
Suomm 2024-03-13 13:34:34 +08:00
commit ccdefba041
4 changed files with 89 additions and 12 deletions

View File

@ -30,7 +30,7 @@ export default defineConfig({
{text: '帮助文档', link: '/zh/intro/what-is-mybatisflex'}, {text: '帮助文档', link: '/zh/intro/what-is-mybatisflex'},
{text: '🆘 常见问题', link: '/zh/faq'}, {text: '🆘 常见问题', link: '/zh/faq'},
{text: '周边 / 视频教程', link: '/zh/awesome-things'}, {text: '周边 / 视频教程', link: '/zh/awesome-things'},
{text: '代码生成器', link: '/zh/others/codegen.md'}, {text: '🍷代码生成器', link: '/zh/others/codegen.md'},
{text: '更新日志', link: '/zh/changes'}, {text: '更新日志', link: '/zh/changes'},
{text: 'JavaDoc', link: 'https://apidoc.gitee.com/mybatis-flex/mybatis-flex/'}, {text: 'JavaDoc', link: 'https://apidoc.gitee.com/mybatis-flex/mybatis-flex/'},

View File

@ -212,10 +212,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` 例如:`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 集成时出错,无法正常启动 MyBatis-Flex
一般情况下,是因为缺少 Nacos 的相关 Maven注意添加如下的 Nacos 依赖: 一般情况下,是因为缺少 Nacos 的相关 Maven注意添加如下的 Nacos 依赖:
@ -237,7 +240,7 @@ FlexConfiguration configuration = new FlexConfiguration();
MybatisFlexBootstrap.getInstance().setConfiguration(configuration); MybatisFlexBootstrap.getInstance().setConfiguration(configuration);
``` ```
2、在使用 Spring-Boot 的场景下: 2、在使用 SpringBoot 的场景下:
```java ```java
@Configuration @Configuration
@ -251,7 +254,7 @@ public class MyConfigurationCustomizer implements ConfigurationCustomizer {
} }
``` ```
3、只使用 Spring不使用 Spring-Boot 的场景: 3、只使用 Spring不使用 SpringBoot 的场景:
```java ```java
@Bean @Bean

View File

@ -1,12 +1,17 @@
# MyBatis-Flex 代码生成器 # 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 ```xml
<dependency> <dependency>
<groupId>com.mybatis-flex</groupId> <groupId>com.mybatis-flex</groupId>
<artifactId>mybatis-flex-codegen</artifactId> <artifactId>mybatis-flex-codegen</artifactId>
@ -122,7 +127,7 @@ public class Codegen {
关闭 APT 的 Mapper 类文件生成,请参考:[APT 设置章节](../others/apt.md) 关闭 APT 的 Mapper 类文件生成,请参考:[APT 设置章节](../others/apt.md)
## 使用介绍 ## 功能介绍
在 Mybatis-Flex 的代码生成器中,支持如下 8 种类型的的产物生成: 在 Mybatis-Flex 的代码生成器中,支持如下 8 种类型的的产物生成:
@ -135,6 +140,8 @@ public class Codegen {
- MapperXml 文件 - MapperXml 文件
- package-info.java 文件 - package-info.java 文件
> 除此之外,我们可以添加扩展生成更多类型的产物,文档参考 [#添加其他产物的生成](#添加其他产物的生成)。
启用或关闭某种类型产物的生成,代码如下: 启用或关闭某种类型产物的生成,代码如下:
```java ```java
@ -155,7 +162,7 @@ globalConfig.enableEntity()
## 全局配置 `GlobalConfig` ## 全局配置 `GlobalConfig`
> 可以像先前一样直接使用 `setXxx()` 进行配置,也可以使用 `getXxxConfig().setXxx()` 进行分类配置。 ### 详细配置
| 获取配置 | 描述 | | 获取配置 | 描述 |
|------------------------|------------------| |------------------------|------------------|
@ -233,7 +240,7 @@ globalConfig.getJavadocConfig()
```java ```java
globalConfig.getPackageConfig() globalConfig.getPackageConfig()
.setSourceDir("D://files/java") .setSourceDir("D:\\files\\java")
.setBasePackage("com.your.domain"); .setBasePackage("com.your.domain");
``` ```
@ -277,7 +284,7 @@ globalConfig.getStrategyConfig()
```java ```java
globalConfig.getTemplateConfig() globalConfig.getTemplateConfig()
.setTemplate(new FreeMarkerTemplate()) .setTemplate(new FreeMarkerTemplate())
.setEntity("D:\your-template-file\my-entity.tpl"); .setEntity("D:\\your-template-file\\my-entity.tpl");
``` ```
## Entity 生成配置 `EntityConfig` ## Entity 生成配置 `EntityConfig`

View File

@ -0,0 +1,67 @@
/*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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 .<br>
* This class should be removed once we drop Java 8 support.
*
* @see <a href=
* "https://bugs.openjdk.java.net/browse/JDK-8161372">https://bugs.openjdk.java.net/browse/JDK-8161372</a>
*/
public static <K, V> V computeIfAbsent(Map<K, V> map, K key, Function<K, V> mappingFunction) {
if (IS_JDK8) {
V value = map.get(key);
if (value != null) {
return value;
}
}
return map.computeIfAbsent(key, mappingFunction);
}
}