提交
This commit is contained in:
68
jeepay-components/jeepay-z-codegen/pom.xml
Normal file
68
jeepay-components/jeepay-z-codegen/pom.xml
Normal file
@@ -0,0 +1,68 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion> <!-- POM模型版本 -->
|
||||
|
||||
<groupId>com.jeequan</groupId> <!-- 组织名, 类似于包名 -->
|
||||
<artifactId>jeepay-z-codegen</artifactId> <!-- 项目名称 -->
|
||||
<packaging>jar</packaging> <!-- 项目的最终打包类型/发布形式, 可选[jar, war, pom, maven-plugin]等 -->
|
||||
<version>1.0-SNAPSHOT</version> <!-- 项目当前版本号 -->
|
||||
<description>Jeepay计全支付系统 [代码生成工具]</description> <!-- 项目描述 -->
|
||||
<url>https://www.jeequan.com</url>
|
||||
|
||||
<!-- 配置属性声明, 支持自定义参数 -->
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <!-- 项目构建输出编码 -->
|
||||
<java.version>1.8</java.version> <!-- 指定java版本号 -->
|
||||
|
||||
</properties>
|
||||
|
||||
<!-- 项目依赖声明 -->
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>8.0.28</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.10</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<version>4.3.10.RELEASE</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-generator</artifactId>
|
||||
<version>3.3.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.velocity</groupId>
|
||||
<artifactId>velocity-engine-core</artifactId>
|
||||
<version>2.3</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>8</source>
|
||||
<target>8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,113 @@
|
||||
package com.gen;
|
||||
|
||||
import com.baomidou.mybatisplus.generator.AutoGenerator;
|
||||
import com.baomidou.mybatisplus.generator.config.*;
|
||||
import com.baomidou.mybatisplus.generator.config.converts.MySqlTypeConvert;
|
||||
import com.baomidou.mybatisplus.generator.config.rules.DateType;
|
||||
import com.baomidou.mybatisplus.generator.config.rules.DbColumnType;
|
||||
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/*
|
||||
* 代码生成器
|
||||
*
|
||||
* @author terrfly
|
||||
* @site https://www.jeepay.vip
|
||||
* @date 2021/6/8 17:47
|
||||
*/
|
||||
public class MainGen {
|
||||
|
||||
public static final String THIS_MODULE_NAME = "jeepay-components/jeepay-z-codegen"; //当前项目名称
|
||||
|
||||
public static final String DB_URL = "jdbc:mysql://rm-bp19g41bnqlws5463no.mysql.rds.aliyuncs.com/syb_jq?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8";
|
||||
public static final String DB_USERNAME = "shouyinbei";
|
||||
public static final String DB_PASSWD = "Shouyinbei16888";
|
||||
|
||||
// 多个用, 拼接
|
||||
//public static final String TABLE_NAMES= "t_sys_entitlement,t_sys_role,t_sys_user,t_sys_user_auth";
|
||||
public static final String TABLE_NAMES= "t_stats_transfer";
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
// 代码生成器
|
||||
AutoGenerator mpg = new AutoGenerator();
|
||||
|
||||
// 全局配置
|
||||
GlobalConfig gc = new GlobalConfig();
|
||||
String projectPath = System.getProperty("user.dir"); //获取当前项目的 文件夹地址
|
||||
|
||||
if(!projectPath.endsWith(THIS_MODULE_NAME)){ //解决IDEA中 项目目录问题
|
||||
projectPath += File.separator + THIS_MODULE_NAME;
|
||||
}
|
||||
|
||||
gc.setOutputDir(projectPath + "/src/main/java");
|
||||
gc.setAuthor("[mybatis plus generator]");
|
||||
gc.setOpen(false);
|
||||
|
||||
gc.setBaseResultMap(true);
|
||||
gc.setDateType(DateType.ONLY_DATE);
|
||||
gc.setServiceImplName("%sService"); //不生成 service接口;
|
||||
|
||||
mpg.setGlobalConfig(gc);
|
||||
|
||||
// 数据源配置
|
||||
DataSourceConfig dsc = new DataSourceConfig();
|
||||
dsc.setUrl(DB_URL);
|
||||
dsc.setDriverName("com.mysql.jdbc.Driver");
|
||||
dsc.setUsername(DB_USERNAME);
|
||||
dsc.setPassword(DB_PASSWD);
|
||||
|
||||
dsc.setTypeConvert(new MySqlTypeConvert() {
|
||||
@Override
|
||||
public DbColumnType processTypeConvert(GlobalConfig globalConfig, String fieldType) {
|
||||
System.out.println("转换类型:" + fieldType);
|
||||
//tinyint转换成Boolean
|
||||
if (fieldType.toLowerCase().contains("tinyint")) {
|
||||
return DbColumnType.BYTE;
|
||||
}
|
||||
return (DbColumnType) super.processTypeConvert(globalConfig, fieldType);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
mpg.setDataSource(dsc);
|
||||
|
||||
// 包配置
|
||||
PackageConfig pc = new PackageConfig();
|
||||
pc.setParent("com.jeequan.jeepay"); //根目录
|
||||
pc.setEntity("db.entity"); //实体目录
|
||||
pc.setMapper("service.mapper"); //Mapper接口目录
|
||||
pc.setXml("service.mapper"); //xml目录
|
||||
|
||||
pc.setService("delete_delete"); //service目录 不需要,暂时删除
|
||||
pc.setServiceImpl("service.impl"); //serviceImpl 目录
|
||||
|
||||
mpg.setPackageInfo(pc);
|
||||
|
||||
// 配置模板
|
||||
TemplateConfig templateConfig = new TemplateConfig();
|
||||
templateConfig.setController(null); //不生成controller
|
||||
templateConfig.setService(null); //不生成services
|
||||
|
||||
mpg.setTemplate(templateConfig);
|
||||
|
||||
|
||||
// 策略配置
|
||||
StrategyConfig strategy = new StrategyConfig();
|
||||
strategy.setNaming(NamingStrategy.underline_to_camel); //no_change原样输出
|
||||
strategy.setColumnNaming(NamingStrategy.underline_to_camel); //no_change原样输出
|
||||
strategy.setEntityLombokModel(true);
|
||||
|
||||
strategy.setInclude(TABLE_NAMES.split(","));
|
||||
strategy.setTablePrefix("t_");
|
||||
|
||||
// strategy.setEntityTableFieldAnnotationEnable(true); //自动添加 field注解
|
||||
|
||||
mpg.setStrategy(strategy);
|
||||
|
||||
mpg.execute();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user