use of com.baomidou.mybatisplus.generator.AutoGenerator in project longmarch by yuyueqty.
the class CodeGenerator method main.
public static void main(String[] args) {
CodeGenerator generator = new CodeGenerator();
// 代码生成器
AutoGenerator mpg = new AutoGenerator();
// 全局配置
mpg.setGlobalConfig(generator.getGlobalConfig());
// 数据源配置
mpg.setDataSource(generator.getDataSourceConfig());
// 包配置
PackageConfig packageConfig = generator.getPackageConfig(modelName);
mpg.setPackageInfo(packageConfig);
// 自定义配置
mpg.setCfg(generator.getInjectionConfig(packageConfig));
// 配置模板
mpg.setTemplate(generator.getTemplateConfig());
// 策略配置
mpg.setStrategy(generator.getStrategyConfig(packageConfig));
mpg.setTemplateEngine(new FreemarkerTemplateEngine());
mpg.execute();
}
use of com.baomidou.mybatisplus.generator.AutoGenerator in project shopzz by whoiszxl.
the class MyBatisCodeGenerator method main.
// 代码生成步骤四:直接运行就能生成了
public static void main(String[] args) {
// 1. 创建代码生成器
AutoGenerator generator = new AutoGenerator();
GlobalConfig gc = new GlobalConfig();
String projectPath = System.getProperty("user.dir");
System.out.println(projectPath);
gc.setOutputDir(projectPath + "/src/main/java");
gc.setAuthor("whoiszxl");
// 生成后是否打开资源管理器
gc.setOpen(false);
// 重新生成时文件是否覆盖
gc.setFileOverride(false);
// 去除Service生成的 I前缀
gc.setServiceName("%sService");
// 主键策略
gc.setIdType(IdType.ID_WORKER);
// 定义生成的实体类中日期类型
gc.setDateType(DateType.ONLY_DATE);
// 开启Swagger2模式
gc.setSwagger2(true);
generator.setGlobalConfig(gc);
// 3、数据源配置
DataSourceConfig dsc = new DataSourceConfig();
dsc.setUrl(URL);
dsc.setDriverName("com.mysql.cj.jdbc.Driver");
dsc.setUsername(USERNAME);
dsc.setPassword(PASSWORD);
dsc.setDbType(DbType.MYSQL);
generator.setDataSource(dsc);
// 4、包配置
PackageConfig pc = new PackageConfig();
// pc.setModuleName("wms"); //模块名
pc.setParent("com.whoiszxl");
pc.setController("controller");
pc.setEntity("entity");
pc.setService("service");
pc.setMapper("mapper");
generator.setPackageInfo(pc);
// 5、策略配置
StrategyConfig strategy = new StrategyConfig();
strategy.setInclude(tableNames);
// 数据库表映射到实体的命名策略
strategy.setNaming(NamingStrategy.underline_to_camel);
// 生成实体时去掉表前缀
strategy.setTablePrefix(tablePrefix);
// 数据库表字段映射到实体的命名策略
strategy.setColumnNaming(NamingStrategy.underline_to_camel);
// lombok 模型 @Accessors(chain = true) setter链式操作
strategy.setEntityLombokModel(true);
// restful api风格控制器
strategy.setRestControllerStyle(true);
// url中驼峰转连字符
strategy.setControllerMappingHyphenStyle(true);
generator.setStrategy(strategy);
// 6、执行
generator.execute();
}
use of com.baomidou.mybatisplus.generator.AutoGenerator in project scaleph by flowerfine.
the class MybatisPlusGenerator method main.
public static void main(String[] args) {
// 自动生成配置
AutoGenerator generator = new AutoGenerator();
generator.setGlobalConfig(globalConfig());
generator.setDataSource(dataSourceConfig());
generator.setPackageInfo(packageConfig());
generator.setStrategy(strategyConfig());
generator.setCfg(injectionConfig());
generator.execute();
}
use of com.baomidou.mybatisplus.generator.AutoGenerator in project Hospital_BackEnd by ZJU-SE-2022-G.
the class CodeGeneratorTest method testCustomTemplateName.
/**
* 自定义模板生成的文件名称
* result: TSimple -> TSimpleEntity
*/
@Test
public void testCustomTemplateName() {
AutoGenerator generator = new AutoGenerator(DATA_SOURCE_CONFIG);
generator.strategy(strategyConfig().entityBuilder().formatFileName("%sEntity").mapperBuilder().formatMapperFileName("%sDao").formatXmlFileName("%sXml").controllerBuilder().formatFileName("%sAction").serviceBuilder().formatServiceFileName("%sService").formatServiceImplFileName("%sServiceImp").build());
generator.global(globalConfig().build());
generator.execute();
}
use of com.baomidou.mybatisplus.generator.AutoGenerator in project Hospital_BackEnd by ZJU-SE-2022-G.
the class CodeGeneratorTest method testLogicDeleteAndIgnoreColumn.
/**
* 逻辑删除字段设置
* result: 新增@TableLogic注解
* 忽略字段设置
* result: 不生成
*/
@Test
public void testLogicDeleteAndIgnoreColumn() {
AutoGenerator generator = new AutoGenerator(DATA_SOURCE_CONFIG);
generator.strategy(strategyConfig().entityBuilder().logicDeleteColumnName(// 基于数据库字段
"deleted").logicDeletePropertyName(// 基于模型属性
"deleteFlag").addIgnoreColumns(// 基于数据库字段
"age").build());
generator.global(globalConfig().build());
generator.execute();
}
Aggregations