use of com.baomidou.mybatisplus.generator.config.StrategyConfig 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.config.StrategyConfig 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.config.StrategyConfig in project vip by guangdada.
the class MyBatisPlusGenerator method main.
public static void main(String[] args) {
AutoGenerator mpg = new AutoGenerator();
// 全局配置
GlobalConfig gc = new GlobalConfig();
// 这里写你自己的java目录
gc.setOutputDir("D:\\ideaSpace\\guns2\\src\\main\\java");
// 是否覆盖
gc.setFileOverride(true);
gc.setActiveRecord(true);
// XML 二级缓存
gc.setEnableCache(false);
// XML ResultMap
gc.setBaseResultMap(true);
// XML columList
gc.setBaseColumnList(false);
gc.setAuthor("chengxg");
mpg.setGlobalConfig(gc);
// 数据源配置
DataSourceConfig dsc = new DataSourceConfig();
dsc.setDbType(DbType.MYSQL);
dsc.setTypeConvert(new MySqlTypeConvert() {
// 自定义数据库表字段类型转换【可选】
@Override
public DbColumnType processTypeConvert(String fieldType) {
return super.processTypeConvert(fieldType);
}
});
dsc.setDriverName("com.mysql.jdbc.Driver");
dsc.setUsername("kkjj");
dsc.setPassword("KKjj111111!@#");
dsc.setUrl("jdbc:mysql://192.168.168.153:3306/vipdb?characterEncoding=utf8");
mpg.setDataSource(dsc);
// 策略配置
StrategyConfig strategy = new StrategyConfig();
// 此处可以修改为您的表前缀
strategy.setTablePrefix(new String[] { "v_" });
// 表名生成策略
strategy.setNaming(NamingStrategy.underline_to_camel);
// 需要生成的表
strategy.setInclude(new String[] { "v_store_coupon" });
mpg.setStrategy(strategy);
// 包配置
PackageConfig pc = new PackageConfig();
pc.setParent(null);
pc.setEntity("com.ikoori.vip.common.persistence.model");
pc.setMapper("com.ikoori.vip.common.persistence.dao");
pc.setXml("com.ikoori.vip.common.persistence.dao.mapping");
// 本项目没用,生成之后删掉
pc.setService("TTT");
// 本项目没用,生成之后删掉
pc.setServiceImpl("TTT");
// 本项目没用,生成之后删掉
pc.setController("TTT");
mpg.setPackageInfo(pc);
// 注入自定义配置,可以在 VM 中使用 cfg.abc 设置的值
InjectionConfig cfg = new InjectionConfig() {
@Override
public void initMap() {
Map<String, Object> map = new HashMap<>();
map.put("abc", this.getConfig().getGlobalConfig().getAuthor() + "-mp");
this.setMap(map);
}
};
mpg.setCfg(cfg);
// 执行生成
mpg.execute();
// 打印注入设置
System.err.println(mpg.getCfg().getMap().get("abc"));
}
use of com.baomidou.mybatisplus.generator.config.StrategyConfig in project finacialpotal by f117-sercet.
the class CodeGenerator method genCode.
@Test
public void genCode() {
// 1、创建代码生成器
AutoGenerator mpg = new AutoGenerator();
// 2、全局配置
GlobalConfig gc = new GlobalConfig();
String projectPath = System.getProperty("user.dir");
gc.setOutputDir(projectPath + "/src/main/java");
gc.setAuthor("Helen");
// 生成后是否打开资源管理器
gc.setOpen(false);
// 去掉Service接口的首字母I
gc.setServiceName("%sService");
// 主键策略
gc.setIdType(IdType.AUTO);
// 开启Swagger2模式
gc.setSwagger2(true);
mpg.setGlobalConfig(gc);
// 3、数据源配置
DataSourceConfig dsc = new DataSourceConfig();
dsc.setUrl("jdbc:mysql://localhost:3306/srb_core?serverTimezone=GMT%2B8&characterEncoding=utf-8");
dsc.setDriverName("com.mysql.cj.jdbc.Driver");
dsc.setUsername("root");
dsc.setPassword("123123");
dsc.setDbType(DbType.MYSQL);
mpg.setDataSource(dsc);
// 4、包配置
PackageConfig pc = new PackageConfig();
pc.setParent("com.atguigu.srb.core");
// 此对象与数据库表结构一一对应,通过 DAO 层向上传输数据源对象。
pc.setEntity("pojo.entity");
mpg.setPackageInfo(pc);
// 5、策略配置
StrategyConfig strategy = new StrategyConfig();
// 数据库表映射到实体的命名策略
strategy.setNaming(NamingStrategy.underline_to_camel);
// 数据库表字段映射到实体的命名策略
strategy.setColumnNaming(NamingStrategy.underline_to_camel);
// lombok
strategy.setEntityLombokModel(true);
// 逻辑删除字段名
strategy.setLogicDeleteFieldName("is_deleted");
// 去掉布尔值的is_前缀(确保tinyint(1))
strategy.setEntityBooleanColumnRemoveIsPrefix(true);
// restful api风格控制器
strategy.setRestControllerStyle(true);
mpg.setStrategy(strategy);
// 6、执行
mpg.execute();
}
use of com.baomidou.mybatisplus.generator.config.StrategyConfig in project spring-boot-student by wyh-spring-ecosystem-student.
the class MyBatisPlusGenerator method main.
public static void main(String[] args) throws SQLException {
// 1. 全局配置
GlobalConfig config = new GlobalConfig();
// 是否支持AR模式
config.setActiveRecord(true).setAuthor(// 作者
"yuhao.wang3").setOutputDir(// 生成路径
"D:\\mybatis-plus").setFileOverride(// 文件覆盖
true).setIdType(// 主键策略
IdType.AUTO).setServiceName(// 设置生成的service接口的名字的首字母是否为I
"%sService").setBaseResultMap(// 生成基本的resultMap
true).setEnableCache(// 是否开启缓存
false).setBaseColumnList(// 生成基本的SQL片段
true);
// 2. 数据源配置
DataSourceConfig dsConfig = new DataSourceConfig();
// 设置数据库类型
dsConfig.setDbType(DbType.MYSQL).setDriverName("com.mysql.jdbc.Driver").setUrl("jdbc:mysql://host:3306/db").setUsername("admin").setPassword("admin");
// 3. 策略配置globalConfiguration中
StrategyConfig stConfig = new StrategyConfig();
// 全局大写命名
stConfig.setCapitalMode(true).setControllerMappingHyphenStyle(true).setRestControllerStyle(true).setEntityLombokModel(true).setColumnNaming(NamingStrategy.underline_to_camel).setNaming(// 数据库表映射到实体的命名策略
NamingStrategy.underline_to_camel).setInclude(// 生成的表
"fis_record_ext");
// 4. 包名策略配置
PackageConfig pkConfig = new PackageConfig();
pkConfig.setParent("com.wlqq.insurance").setMapper(// dao
"mybatis.mapper.withSharding").setService(// servcie
"service").setController(// controller
"controller").setEntity("mybatis.domain").setXml(// mapper.xml
"mapper-xml");
// 5. 整合配置
AutoGenerator ag = new AutoGenerator();
ag.setGlobalConfig(config).setDataSource(dsConfig).setStrategy(stConfig).setPackageInfo(pkConfig);
// 6. 执行
ag.execute();
}
Aggregations