use of com.baomidou.mybatisplus.generator.config.GlobalConfig in project heifer by galaxy-sea.
the class GeneratorCode method globalConfig.
/**
* 全局配置
*
* @return
*/
private static synchronized GlobalConfig globalConfig() {
String projectPath = System.getProperty("user.dir");
GlobalConfig gc = new GlobalConfig();
gc.setOutputDir(projectPath + "/src/main/java");
gc.setFileOverride(true);
gc.setOpen(false);
gc.setEnableCache(false);
gc.setAuthor(author);
gc.setKotlin(false);
gc.setSwagger2(true);
// gc.setActiveRecord();
gc.setBaseResultMap(true);
gc.setDateType(DateType.ONLY_DATE);
gc.setBaseColumnList(true);
// gc.setEntityName("%sDo");
gc.setMapperName("%sDao");
// gc.setXmlName();
gc.setServiceName("%s" + ConstVal.SERVICE);
// gc.setServiceImplName();
// gc.setControllerName();
gc.setIdType(IdType.ASSIGN_ID);
return gc;
}
use of com.baomidou.mybatisplus.generator.config.GlobalConfig 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.config.GlobalConfig in project scaleph by flowerfine.
the class MybatisPlusGenerator method globalConfig.
/**
* 全局配置
*
* @return GlobalConfig
*/
private static GlobalConfig globalConfig() {
GlobalConfig config = new GlobalConfig();
String projectPath = System.getProperty("user.dir");
config.setOutputDir(projectPath + "/scaleph-support/scaleph-generator/src/main/java/");
config.setAuthor(AUTHOR);
config.setOpen(false);
config.setFileOverride(true);
config.setBaseResultMap(true);
config.setDateType(DateType.ONLY_DATE);
config.setBaseColumnList(false);
config.setIdType(IdType.AUTO);
config.setMapperName("%sMapper");
config.setXmlName("%sMapper");
config.setEntityName("%s");
config.setServiceName("%sService");
config.setServiceImplName("%sServiceImpl");
config.setControllerName("%sController");
config.setSwagger2(true);
return config;
}
use of com.baomidou.mybatisplus.generator.config.GlobalConfig in project tutorials-java by Artister.
the class MysqlGenerator method main.
/**
* RUN THIS
*/
public static void main(String[] args) {
// 代码生成器
AutoGenerator mpg = new AutoGenerator();
// 全局配置
GlobalConfig gc = new GlobalConfig();
String projectPath = System.getProperty("user.dir");
gc.setOutputDir(projectPath + "/mybatis-plus-sample-generator/src/main/java");
gc.setAuthor("jobob");
gc.setOpen(false);
mpg.setGlobalConfig(gc);
// 数据源配置
DataSourceConfig dsc = new DataSourceConfig();
dsc.setUrl("jdbc:mysql://localhost:3306/ant?useUnicode=true&useSSL=false&characterEncoding=utf8");
// dsc.setSchemaName("public");
dsc.setDriverName("com.mysql.jdbc.Driver");
dsc.setUsername("root");
dsc.setPassword("1q2w3e4r");
mpg.setDataSource(dsc);
// 包配置
PackageConfig pc = new PackageConfig();
pc.setModuleName(scanner("模块名"));
pc.setParent("com.baomidou.mybatisplus.samples.generator");
mpg.setPackageInfo(pc);
// 自定义配置
InjectionConfig cfg = new InjectionConfig() {
@Override
public void initMap() {
// to do nothing
}
};
List<FileOutConfig> focList = new ArrayList<>();
focList.add(new FileOutConfig("/templates/mapper.xml.ftl") {
@Override
public String outputFile(TableInfo tableInfo) {
// 自定义输入文件名称
return projectPath + "/mybatis-plus-sample-generator/src/main/resources/mapper/" + pc.getModuleName() + "/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
}
});
cfg.setFileOutConfigList(focList);
mpg.setCfg(cfg);
mpg.setTemplate(new TemplateConfig().setXml(null));
// 策略配置
StrategyConfig strategy = new StrategyConfig();
strategy.setNaming(NamingStrategy.underline_to_camel);
strategy.setColumnNaming(NamingStrategy.underline_to_camel);
strategy.setSuperEntityClass("com.baomidou.mybatisplus.samples.generator.common.BaseEntity");
strategy.setEntityLombokModel(true);
strategy.setSuperControllerClass("com.baomidou.mybatisplus.samples.generator.common.BaseController");
strategy.setInclude(scanner("表名"));
strategy.setSuperEntityColumns("id");
strategy.setControllerMappingHyphenStyle(true);
strategy.setTablePrefix(pc.getModuleName() + "_");
mpg.setStrategy(strategy);
// 选择 freemarker 引擎需要指定如下加,注意 pom 依赖必须有!
mpg.setTemplateEngine(new FreemarkerTemplateEngine());
mpg.execute();
}
Aggregations