feat: add code generator
This commit is contained in:
@@ -65,6 +65,15 @@
|
|||||||
<artifactId>wfc-common-swagger</artifactId>
|
<artifactId>wfc-common-swagger</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wfc</groupId>
|
||||||
|
<artifactId>wfc-common-mybatis</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-generator</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@@ -1,10 +1,5 @@
|
|||||||
package org.wfc.gen.controller;
|
package org.wfc.gen.controller;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
@@ -28,6 +23,12 @@ import org.wfc.gen.domain.GenTableColumn;
|
|||||||
import org.wfc.gen.service.IGenTableColumnService;
|
import org.wfc.gen.service.IGenTableColumnService;
|
||||||
import org.wfc.gen.service.IGenTableService;
|
import org.wfc.gen.service.IGenTableService;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 代码生成 操作处理
|
* 代码生成 操作处理
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
package org.wfc.gen.util;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||||
|
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
|
||||||
|
import com.baomidou.mybatisplus.generator.config.OutputFile;
|
||||||
|
import com.baomidou.mybatisplus.generator.config.rules.DateType;
|
||||||
|
import com.baomidou.mybatisplus.generator.config.rules.DbColumnType;
|
||||||
|
import com.baomidou.mybatisplus.generator.fill.Column;
|
||||||
|
import org.wfc.common.mybatis.domain.BaseData;
|
||||||
|
|
||||||
|
import java.sql.Types;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 代码生成器工具
|
||||||
|
* @author: cyc
|
||||||
|
* @since: 2024-12-06
|
||||||
|
*/
|
||||||
|
public class GenPlusUtils {
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
FastAutoGenerator.create("jdbc:mysql://localhost:3306/wfc-user-db?useUnicode=true&useSSL=false&characterEncoding=utf8", "root", "123456")
|
||||||
|
.globalConfig(builder -> {
|
||||||
|
builder.author("cyc") // 设置作者
|
||||||
|
.enableSpringdoc()
|
||||||
|
.dateType(DateType.ONLY_DATE)
|
||||||
|
.outputDir("D://gencode"); // 指定输出目录
|
||||||
|
})
|
||||||
|
.dataSourceConfig(builder ->
|
||||||
|
builder.typeConvertHandler((globalConfig, typeRegistry, metaInfo) -> {
|
||||||
|
int typeCode = metaInfo.getJdbcType().TYPE_CODE;
|
||||||
|
if (typeCode == Types.SMALLINT) {
|
||||||
|
// 自定义类型转换
|
||||||
|
return DbColumnType.INTEGER;
|
||||||
|
}
|
||||||
|
if (typeCode == Types.CHAR) {
|
||||||
|
// 自定义类型转换
|
||||||
|
return DbColumnType.BOOLEAN;
|
||||||
|
}
|
||||||
|
return typeRegistry.getColumnType(metaInfo);
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.packageConfig(builder ->
|
||||||
|
builder.parent("org.wfc") // 设置父包名
|
||||||
|
.moduleName("user") // 设置父包模块名
|
||||||
|
.entity("domain")
|
||||||
|
.pathInfo(Collections.singletonMap(OutputFile.xml, "D://gencode")) // 设置mapperXml生成路径
|
||||||
|
)
|
||||||
|
.strategyConfig(builder ->
|
||||||
|
builder.addInclude("u_cdr_detail") // 设置需要生成的表名
|
||||||
|
.addTablePrefix("t_", "c_") // 设置过滤表前缀
|
||||||
|
.controllerBuilder()
|
||||||
|
.enableRestStyle()
|
||||||
|
.entityBuilder()
|
||||||
|
.enableLombok()
|
||||||
|
.enableFileOverride()
|
||||||
|
.superClass(BaseData.class)
|
||||||
|
.addSuperEntityColumns("id", "create_by", "create_time", "update_by", "update_time", "del_flag")
|
||||||
|
.addTableFills(new Column("create_time", FieldFill.INSERT))
|
||||||
|
.addTableFills(new Column("update_time", FieldFill.INSERT_UPDATE))
|
||||||
|
.addTableFills(new Column("create_by", FieldFill.INSERT))
|
||||||
|
.addTableFills(new Column("update_by", FieldFill.INSERT_UPDATE))
|
||||||
|
.controllerBuilder()
|
||||||
|
.enableRestStyle()
|
||||||
|
.serviceBuilder()
|
||||||
|
.enableFileOverride()
|
||||||
|
.mapperBuilder()
|
||||||
|
.enableFileOverride()
|
||||||
|
)
|
||||||
|
.execute();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user