提交 d440f4a0 编写于 作者: 布熬夜了's avatar 布熬夜了

修改:代码优化

上级 468c1fc6
......@@ -18,10 +18,23 @@
</build>
<properties>
<!-- Java环境配置 -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>17</java.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<!-- 插件依赖 -->
<maven.plugin.api.version>3.9.0</maven.plugin.api.version>
<maven.plugin.annotations>3.8.1</maven.plugin.annotations>
<!-- MyBatis-Plus依赖 -->
<mybatis.plus.version>3.5.3.1</mybatis.plus.version>
<!-- 代码生成器引擎依赖 -->
<velocity.version>2.3</velocity.version>
<jakarta.version>3.0.2</jakarta.version>
<!-- 数据库驱动依赖 -->
<mysql.driver.version>8.0.30</mysql.driver.version>
<!-- 代码简化依赖 -->
<lambok.version>1.18.26</lambok.version>
</properties>
<packaging>maven-plugin</packaging>
......@@ -30,50 +43,50 @@
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.9.0</version>
<version>${maven.plugin.api.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.8.1</version>
<version>${maven.plugin.annotations}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.3.1</version>
<version>${mybatis.plus.version}</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>3.5.3.1</version>
<version>${mybatis.plus.version}</version>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>
<version>2.3</version>
<version>${velocity.version}</version>
</dependency>
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
<version>3.0.2</version>
<version>${jakarta.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.30</version>
<version>${mysql.driver.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.26</version>
<version>${lambok.version}</version>
</dependency>
</dependencies>
</project>
......@@ -92,4 +92,9 @@ public class GeneratorDto {
* 是否覆盖已生成文件
*/
private Boolean override;
/**
* 数据库类型
*/
private String databaseType;
}
package com.catalpa.commons.mojo;
import com.baomidou.mybatisplus.annotation.DbType;
import com.catalpa.commons.dto.GeneratorDto;
import com.catalpa.commons.utils.GeneratorUtil;
import org.apache.maven.plugin.AbstractMojo;
......@@ -142,6 +143,7 @@ public class GeneratorMojo extends AbstractMojo {
generatorDto.setUserName(userName);
generatorDto.setUserPassword(userPassword);
generatorDto.setTableName(tableName);
generatorDto.setDatabaseType(DbType.MYSQL.getDb());
new GeneratorUtil(generatorDto).generate();
}
......
......@@ -172,7 +172,7 @@ public class GeneratorUtil {
private DataSourceConfig.Builder dataSourceConfig() {
String databaseUrl = "";
// MySQL数据库支持
if (DbType.getDbType("mysql") == DbType.MYSQL) {
if (DbType.getDbType(generatorDto.getDatabaseType()) == DbType.MYSQL) {
databaseUrl = "jdbc:mysql://" + generatorDto.getIp() + ":" + generatorDto.getPort() + "/" + generatorDto.getDatabaseName() + "?&useSSL=true&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai";
}
return new DataSourceConfig.Builder(databaseUrl, generatorDto.getUserName(), generatorDto.getUserPassword());
......@@ -181,7 +181,7 @@ public class GeneratorUtil {
/**
* 重写Dto生成方法的路径
*/
public class EnhanceFreemarkerTemplateEngine extends VelocityTemplateEngine {
public static class EnhanceFreemarkerTemplateEngine extends VelocityTemplateEngine {
public void outputCustomFile(@NotNull List<CustomFile> customFiles, @NotNull TableInfo tableInfo, @NotNull Map<String, Object> objectMap) {
String entityName = tableInfo.getEntityName();
String parentPath = this.getPathInfo(OutputFile.parent) + "/" + objectMap.get("dtoPackage");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册