use of com.baomidou.mybatisplus.generator.AutoGenerator in project coding-more by itwanger.
the class CodeGenerator method main.
public static void main(String[] args) {
// 代码生成器
AutoGenerator mpg = new AutoGenerator();
// 全局配置
GlobalConfig gc = new GlobalConfig();
String projectPath = System.getProperty("user.dir");
gc.setOutputDir("d:/test" + "/src/main/java");
gc.setAuthor("石磊");
gc.setOpen(false);
gc.setDateType(DateType.ONLY_DATE);
gc.setSwagger2(true);
gc.setIdType(IdType.AUTO);
gc.setBaseColumnList(true);
gc.setBaseResultMap(true);
gc.setFileOverride(true);
mpg.setGlobalConfig(gc);
// 数据源配置
DataSourceConfig dsc = new DataSourceConfig();
dsc.setUrl("jdbc:mysql://118.190.99.232:3306/codingmoretiny02?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai");
dsc.setDriverName("com.mysql.cj.jdbc.Driver");
dsc.setUsername("codingmoretiny02");
dsc.setPassword("Xw5y8bGFzb86DyGy");
mpg.setDataSource(dsc);
// 包配置
PackageConfig pc = new PackageConfig();
pc.setParent("com.codingmore");
mpg.setPackageInfo(pc);
pc.setEntity("model");
// 策略配置,去掉就是生成全部,留下就是生成专属表的
StrategyConfig strategy = new StrategyConfig();
strategy.setNaming(NamingStrategy.underline_to_camel);
strategy.setColumnNaming(NamingStrategy.underline_to_camel);
// strategy.setSuperEntityClass("你自己的父类实体,没有就不用设置!");
strategy.setEntityLombokModel(true);
strategy.setInclude(scanner("表名,多个英文逗号分割").split(","));
strategy.setControllerMappingHyphenStyle(true);
mpg.setStrategy(strategy);
mpg.execute();
}
use of com.baomidou.mybatisplus.generator.AutoGenerator in project Resource by lovelifeming.
the class MBPlusTest method main.
public static void main(String[] args) {
AutoGenerator ag = new AutoGenerator();
// 全局配置
GlobalConfig gc = new GlobalConfig();
// gc.setOutputDir("D:\\workspace\\SpringBoot\\src\\main\\java");//将代码生成在项目中
// 将代码生成在指定目录中
gc.setOutputDir(System.getProperty("user.dir") + "/src/main/java");
gc.setFileOverride(true);
// 不需要ActiveRecord特性的请改为false
gc.setActiveRecord(false);
// XML 二级缓存
gc.setEnableCache(false);
// XML ResultMap
gc.setBaseResultMap(true);
// XML columnList
gc.setBaseColumnList(false);
// 作者
gc.setAuthor("zsm");
// 只生成java.util.Date类型时间格式
gc.setDateType(DateType.ONLY_DATE);
// 自定义文件命名,注意 %s 会自动填充表实体属性
gc.setControllerName("%sController");
gc.setServiceName("%sService");
gc.setServiceImplName("%sServiceImpl");
gc.setMapperName("%sMapper");
gc.setXmlName("%sMapper");
ag.setGlobalConfig(gc);
// 数据源配置
DataSourceConfig dsc = new DataSourceConfig();
// 设置数据库类型
dsc.setDbType(DbType.MYSQL);
dsc.setDriverName("com.mysql.jdbc.Driver");
dsc.setUsername("root");
dsc.setPassword("123456");
dsc.setUrl("jdbc:mysql://127.0.0.1:3306/test_db?characterEncoding=utf-8");
ag.setDataSource(dsc);
// 策略配置
StrategyConfig strategy = new StrategyConfig();
// strategy.setCapitalMode(true); // 全局大写命名 ORACLE 注意
// 此处可以修改为您的表前缀
strategy.setTablePrefix(new String[] { "tb_" });
// 表名生成策略
strategy.setNaming(NamingStrategy.underline_to_camel);
// 需要生成的表
strategy.setInclude(new String[] { "tb_user", "tb_order" });
// strategy.setExclude(new String[]{"tb_test"}); // 排除生成的表
// 自定义 service 父类
strategy.setSuperServiceClass(null);
strategy.setSuperServiceImplClass(null);
strategy.setSuperMapperClass(null);
// 自定义实体父类
// strategy.setSuperEntityClass(com.zsm.sb.entity.BaseEntity);
// 自定义实体,公共字段
// strategy.setSuperEntityColumns(new String[] { "test_id", "userId" });
// 自定义 mapper 父类
// strategy.setSuperMapperClass("com.zsm.sb.mapper.BaseMapper");
// 自定义 service 父类
// strategy.setSuperServiceClass("com.zsm.sb.service.BaseService");
// 自定义 service 实现类父类
// strategy.setSuperServiceImplClass("com.zsm.sb.service.BaseServiceImpl");
// 自定义 controller 父类
// strategy.setSuperControllerClass("com.zsm.sb.controller.BaseController");
// 实体是否生成字段常量(默认 false)
// public static final String ID = "userId";
// strategy.setEntityColumnConstant(true);
// 实体是否为构建者模型(默认 false)
// public User setName(String name) {this.name = name; return this;}
// strategy.setEntityBuilderModel(true);
ag.setStrategy(strategy);
// 生成代码包名配置
PackageConfig pc = new PackageConfig();
pc.setParent("com.zsm.sb");
pc.setController("controller");
pc.setService("service");
pc.setServiceImpl("service.impl");
pc.setMapper("dao");
pc.setEntity("model");
pc.setXml("mapper");
ag.setPackageInfo(pc);
// 自定义 xxList.jsp 生成
List<FileOutConfig> focList = new ArrayList<FileOutConfig>();
// focList.add(new FileOutConfig("/template/list.jsp.vm") {
// @Override
// public String outputFile(TableInfo tableInfo) {
// // 自定义输入文件名称
// return "D://my_" + tableInfo.getEntityName() + ".jsp";
// }
// });
// cfg.setFileOutConfigList(focList);
// mpg.setCfg(cfg);
// 执行生成
ag.execute();
}
use of com.baomidou.mybatisplus.generator.AutoGenerator in project demo-parent by yindanqing925.
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") + "/mybatisplus-demo";
gc.setOutputDir(projectPath + "/src/main/java");
// TODO 设置用户名
gc.setAuthor("yindanqing");
gc.setOpen(false);
// service 命名方式
gc.setServiceName("%sService");
// service impl 命名方式
gc.setServiceImplName("%sServiceImpl");
// 自定义文件命名,注意 %s 会自动填充表实体属性!
gc.setMapperName("%sMapper");
gc.setXmlName("%sMapper");
gc.setFileOverride(true);
gc.setActiveRecord(true);
// XML 二级缓存
gc.setEnableCache(false);
// XML ResultMap
gc.setBaseResultMap(true);
// XML columList
gc.setBaseColumnList(false);
mpg.setGlobalConfig(gc);
// TODO 数据源配置
DataSourceConfig dsc = new DataSourceConfig();
dsc.setUrl("jdbc:mysql://cdb-1v2wt3os.bj.tencentcdb.com:10243/nh?useUnicode=true&characterEncoding=UTF8");
dsc.setDriverName("com.mysql.jdbc.Driver");
dsc.setUsername("user_dev");
dsc.setPassword("user_dev_nh");
mpg.setDataSource(dsc);
// TODO 包配置
PackageConfig pc = new PackageConfig();
// pc.setModuleName(scanner("模块名"));
pc.setParent("org.nh.mybatisplus.dict");
pc.setEntity("domain");
pc.setService("service");
pc.setServiceImpl("service.impl");
mpg.setPackageInfo(pc);
// 自定义需要填充的字段
List<TableFill> tableFillList = new ArrayList<>();
// 如 每张表都有一个创建时间、修改时间
// 而且这基本上就是通用的了,新增时,创建时间和修改时间同时修改
// 修改时,修改时间会修改,
// 虽然像Mysql数据库有自动更新几只,但像ORACLE的数据库就没有了,
// 使用公共字段填充功能,就可以实现,自动按场景更新了。
// 如下是配置
// TableFill createField = new TableFill("gmt_create", FieldFill.INSERT);
// TableFill modifiedField = new TableFill("gmt_modified", FieldFill.INSERT_UPDATE);
// tableFillList.add(createField);
// tableFillList.add(modifiedField);
// 自定义配置
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 + "/src/main/java/org/nh/mybatisplus/dict/mapper/" + tableInfo.getEntityName() + "Mapper" + ".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.setEntityLombokModel(true);
// 设置逻辑删除键
strategy.setLogicDeleteFieldName("deleted");
// TODO 指定生成的bean的数据库表名
strategy.setInclude("transfer_dict");
// strategy.setSuperEntityColumns("id");
// 驼峰转连字符
strategy.setControllerMappingHyphenStyle(true);
mpg.setStrategy(strategy);
// 选择 freemarker 引擎需要指定如下加,注意 pom 依赖必须有!
mpg.setTemplateEngine(new FreemarkerTemplateEngine());
mpg.execute();
}
use of com.baomidou.mybatisplus.generator.AutoGenerator in project haha by hahafreeasair666.
the class MybatisPlusConfig method main.
/**
* <p>
* mysql 自动生成工具
* </p>
*/
public static void main(String[] args) {
AutoGenerator mpg = new AutoGenerator();
String url = MybatisPlusConfig.class.getClassLoader().getResource("").getPath();
File file = new File(url);
String projectPath = file.getParentFile().getParentFile().getAbsolutePath();
String srcPath = projectPath + File.separator + "src" + File.separator + "main" + File.separator + "java";
// System.out.println(url);
// System.out.println(projectPath);
System.out.println("源代码将生成到(包会自动创建):" + srcPath);
// 全局配置
GlobalConfig gc = new GlobalConfig();
gc.setOutputDir(srcPath);
gc.setServiceName("%sService");
gc.setFileOverride(true);
gc.setActiveRecord(true);
// XML 二级缓存
gc.setEnableCache(false);
// XML ResultMap
gc.setBaseResultMap(true);
// XML columList
gc.setBaseColumnList(false);
gc.setAuthor("");
gc.setKotlin(false);
// 自定义文件命名,注意 %s 会自动填充表实体属性!
// gc.setMapperName("%sDao");
// gc.setXmlName("%sDao");
// gc.setServiceName("MP%sService");
// gc.setServiceImplName("%sServiceDiy");
// gc.setControllerName("%sAction");
mpg.setGlobalConfig(gc);
// 数据源配置
DataSourceConfig dsc = new DataSourceConfig();
dsc.setDbType(DbType.MYSQL);
dsc.setTypeConvert(new MySqlTypeConvert() {
// 自定义数据库表字段类型转换【可选】
@Override
public DbColumnType processTypeConvert(String fieldType) {
System.out.println("转换类型:" + fieldType);
return super.processTypeConvert(fieldType);
}
});
dsc.setDriverName("com.mysql.jdbc.Driver");
dsc.setUsername("root");
dsc.setPassword("a123456+");
dsc.setUrl("jdbc:mysql://gz-cdb-mfro5399.sql.tencentcdb.com:63292/hahaapi?characterEncoding=utf8");
mpg.setDataSource(dsc);
// 策略配置
StrategyConfig strategy = new StrategyConfig();
// strategy.setTablePrefix(new String[] { "adconfig_" });// 此处可以修改为您的表前缀
// strategy.setNaming(NamingStrategy.removePrefixAndCamel(name,new
// String[]{"t_"}));// 表名生成策略
// strategy.setExclude(new String[] { "productinfo", "view_product_spec"
// }); // 排除生成的表
//
strategy.setInclude(new String[] { "adoptionfeedback" });
// 需要生成的表
// 字段名生成策略
strategy.setNaming(NamingStrategy.underline_to_camel);
// 逻辑删除字段
strategy.setLogicDeleteFieldName("isdel");
// 自定义实体父类
// strategy.setSuperEntityClass("com.fcs.demo.TestEntity");
// 自定义实体,公共字段
// strategy.setSuperEntityColumns(new String[] { "is_del",
// "create_time", "update_time" });
// 自定义 mapper 父类
// strategy.setSuperMapperClass("com.fcs.demo.TestMapper");
// 自定义 testservice 父类
// strategy.setSuperServiceClass("com.fcs.demo.TestService");
// 自定义 testservice 实现类父类
// strategy.setSuperServiceImplClass("com.fcs.demo.TestServiceImpl");
// 自定义 controller 父类
// strategy.setSuperControllerClass("com.fcs.demo.TestController");
// 【实体】是否生成字段常量(默认 false)
// public static final String ID = "test_id";
// strategy.setEntityColumnConstant(true);
// 【实体】是否为构建者模型(默认 false)
// public User setName(String name) {this.name = name; return this;}
// strategy.setEntityBuliderModel(true);
mpg.setStrategy(strategy);
// 包配置
PackageConfig pc = new PackageConfig();
pc.setParent("com.ch999.haha");
pc.setModuleName("admin");
pc.setController("controller");
mpg.setPackageInfo(pc);
// 注入自定义配置,可以在 VM 中使用 cfg.abc 设置的值
// InjectionConfig cfg = new InjectionConfig() {
// @Override
// public void initMap() {
// Map<String, Object> map = new HashMap<String, Object>();
// map.put("abc", this.getConfig().getGlobalConfig().getAuthor() +
// "-mp");
// this.setMap(map);
// }
// };
// // 自定义 xxList.jsp 生成
// List<FileOutConfig> focList = new ArrayList<FileOutConfig>();
// focList.add(new FileOutConfig("/template/list.jsp.vm") {
// @Override
// public String outputFile(TableInfo tableInfo) {
// // 自定义输入文件名称
// return "D://my_" + tableInfo.getEntityName() + ".jsp";
// }
// });
// cfg.setFileOutConfigList(focList);
// mpg.setCfg(cfg);
// 自定义模板配置,可以 copy 源码 mybatis-plus/src/main/resources/template 下面内容修改,
// 放置自己项目的 src/main/resources/template 目录下, 默认名称一下可以不配置,也可以自定义模板名称
// TemplateConfig tc = new TemplateConfig();
// tc.setController("...");
// tc.setEntity("...");
// tc.setMapper("...");
// tc.setXml("...");
// tc.setService("...");
// tc.setServiceImpl("...");
// mpg.setTemplate(tc);
// 执行生成
mpg.execute();
// 打印注入设置
// System.err.println(mpg.getCfg().getMap().get("abc"));
}
use of com.baomidou.mybatisplus.generator.AutoGenerator in project neweagle-api by apgzs.
the class GeneratorTest method gen.
@Test
public void gen() {
AutoGenerator mpg = new AutoGenerator();
// 全局配置
GlobalConfig gc = new GlobalConfig();
gc.setOutputDir(OUTPUT);
gc.setFileOverride(true);
gc.setActiveRecord(true);
// XML 二级缓存
gc.setEnableCache(false);
// XML ResultMap
gc.setBaseResultMap(false);
// XML columList
gc.setBaseColumnList(false);
gc.setAuthor(AUTHOR);
// 自定义文件命名,注意 %s 会自动填充表实体属性!
// gc.setMapperName("%sDao");
// gc.setXmlName("%sDao");
// gc.setServiceName("MP%sService");
// gc.setServiceImplName("%sServiceDiy");
// gc.setControllerName("%sAction");
mpg.setGlobalConfig(gc);
// 数据源配置
DataSourceConfig dsc = new DataSourceConfig();
dsc.setDbType(DbType.MYSQL);
dsc.setTypeConvert(new MySqlTypeConvert() {
// 自定义数据库表字段类型转换【可选】
@Override
public DbColumnType processTypeConvert(String fieldType) {
System.out.println("转换类型:" + fieldType);
return super.processTypeConvert(fieldType);
}
});
dsc.setDriverName("com.mysql.jdbc.Driver");
dsc.setUsername(DB_USER);
dsc.setPassword(DB_PASS);
dsc.setUrl(DB_URL);
mpg.setDataSource(dsc);
// 策略配置
StrategyConfig strategy = new StrategyConfig();
// strategy.setCapitalMode(true);// 全局大写命名 ORACLE 注意
// strategy.setTablePrefix(new String[] { "book_","sys_"});// 此处可以修改为您的表前缀
// 表名生成策略
strategy.setNaming(NamingStrategy.underline_to_camel);
strategy.setSuperControllerClass("com.neweagle.api.comm.web.base.SuperController");
strategy.setSuperMapperClass("com.neweagle.api.comm.plugin.mybatisplus.SuperMapper");
// 需要生成的表
strategy.setInclude(TABLE);
// strategy.setExclude(new String[]{"test"}); // 排除生成的表
// 自定义实体父类
strategy.setSuperEntityClass("com.neweagle.api.comm.plugin.mybatisplus.SuperEntity");
// 自定义实体,公共字段
strategy.setSuperEntityColumns(new String[] { "id", "create_time", "update_time" });
// 自定义 mapper 父类
// strategy.setSuperMapperClass("com.baomidou.demo.TestMapper");
// 自定义 service 父类
// strategy.setSuperServiceClass("com.baomidou.demo.TestService");
// 自定义 service 实现类父类
// strategy.setSuperServiceImplClass("com.baomidou.demo.TestServiceImpl");
// 自定义 web 父类
// strategy.setSuperControllerClass("com.baomidou.demo.TestController");
// 【实体】是否生成字段常量(默认 false)
// public static final String ID = "test_id";
// strategy.setEntityColumnConstant(true);
// 【实体】是否为构建者模型(默认 false)
// public User setName(String name) {this.name = name; return this;}
// strategy.setEntityBuliderModel(true);
mpg.setStrategy(strategy);
// 包配置
PackageConfig pc = new PackageConfig();
pc.setParent("com.neweagle.api.module");
pc.setModuleName(MODULE);
mpg.setPackageInfo(pc);
// 注入自定义配置,可以在 VM 中使用 cfg.abc 设置的值
InjectionConfig cfg = new InjectionConfig() {
@Override
public void initMap() {
Map<String, Object> map = new HashMap<String, Object>();
map.put("abc", this.getConfig().getGlobalConfig().getAuthor() + "-mp");
this.setMap(map);
}
};
// // 自定义 xxList.jsp 生成
// List<FileOutConfig> focList = new ArrayList<FileOutConfig>();
// focList.add(new FileOutConfig("/template/list.jsp.vm") {
// @Override
// public String outputFile(TableInfo tableInfo) {
// // 自定义输入文件名称
// return "D://my_" + tableInfo.getEntityName() + ".jsp";
// }
// });
// cfg.setFileOutConfigList(focList);
mpg.setCfg(cfg);
// 执行生成
mpg.execute();
// 打印注入设置
System.err.println(mpg.getCfg().getMap().get("abc"));
}
Aggregations