com.baomidou.mybatisplus.generator.config.rules.DbType Java Examples
The following examples show how to use
com.baomidou.mybatisplus.generator.config.rules.DbType.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GunsGeneratorConfig.java From MeetingFilm with Apache License 2.0 | 5 votes |
protected void dataSourceConfig() { dataSourceConfig.setDbType(DbType.MYSQL); dataSourceConfig.setDriverName("com.mysql.jdbc.Driver"); dataSourceConfig.setUsername("root"); dataSourceConfig.setPassword("root"); dataSourceConfig.setUrl("jdbc:mysql://127.0.0.1:3306/guns?characterEncoding=utf8"); }
Example #2
Source File: GeneratorServiceEntity.java From express-ssm with Apache License 2.0 | 5 votes |
private void generateByTables(boolean serviceNameStartWithI, String packageName, String... tableNames) { GlobalConfig config = new GlobalConfig(); String dbUrl = "jdbc:mysql://localhost:3306/express"; DataSourceConfig dataSourceConfig = new DataSourceConfig(); dataSourceConfig.setDbType(DbType.MYSQL) .setUrl(dbUrl) .setUsername("root") .setPassword("root") .setDriverName("com.mysql.jdbc.Driver"); StrategyConfig strategyConfig = new StrategyConfig(); strategyConfig .setCapitalMode(true) .setEntityLombokModel(false) .setDbColumnUnderline(true) .setNaming(NamingStrategy.underline_to_camel) .setInclude(tableNames); config.setActiveRecord(false) .setEnableCache(false) // XML 二级缓存 .setAuthor("jitwxs") .setOutputDir("d:\\codeGen") .setFileOverride(true); if (!serviceNameStartWithI) { config.setServiceName("%sService"); } new AutoGenerator().setGlobalConfig(config) .setDataSource(dataSourceConfig) .setStrategy(strategyConfig) .setPackageInfo( new PackageConfig() .setParent(packageName) .setController("controller") .setEntity("pojo") ).execute(); }
Example #3
Source File: GeneratorServiceEntity.java From blog-sample with Apache License 2.0 | 5 votes |
private void generateByTables(boolean serviceNameStartWithI, String packageName, String... tableNames) { GlobalConfig config = new GlobalConfig(); String dbUrl = "jdbc:mysql://localhost:3306/payment"; DataSourceConfig dataSourceConfig = new DataSourceConfig(); dataSourceConfig.setDbType(DbType.MYSQL) .setUrl(dbUrl) .setUsername("root") .setPassword("root") .setDriverName("com.mysql.jdbc.Driver"); StrategyConfig strategyConfig = new StrategyConfig(); strategyConfig .setCapitalMode(true) .setEntityLombokModel(false) .setDbColumnUnderline(true) .setNaming(NamingStrategy.underline_to_camel) .setInclude(tableNames); config.setActiveRecord(false) .setEnableCache(false) // XML 二级缓存 .setAuthor("jitwxs") .setOutputDir("d:\\codeGen") .setFileOverride(true); if (!serviceNameStartWithI) { config.setServiceName("%sService"); } new AutoGenerator().setGlobalConfig(config) .setDataSource(dataSourceConfig) .setStrategy(strategyConfig) .setPackageInfo( new PackageConfig() .setParent(packageName) .setController("controller") .setEntity("entity") ).execute(); }
Example #4
Source File: GeneratorServiceEntity.java From blog-sample with Apache License 2.0 | 5 votes |
private void generateByTables(boolean serviceNameStartWithI, String packageName, String... tableNames) { GlobalConfig config = new GlobalConfig(); String dbUrl = "jdbc:mysql://localhost:3306/test1"; DataSourceConfig dataSourceConfig = new DataSourceConfig(); dataSourceConfig.setDbType(DbType.MYSQL) .setUrl(dbUrl) .setUsername("root") .setPassword("root") .setDriverName("com.mysql.jdbc.Driver"); StrategyConfig strategyConfig = new StrategyConfig(); strategyConfig .setCapitalMode(true) .setEntityLombokModel(false) .setDbColumnUnderline(true) .setNaming(NamingStrategy.underline_to_camel) .setInclude(tableNames); config.setActiveRecord(false) .setEnableCache(false) // XML 二级缓存 .setAuthor("jitwxs") .setOutputDir("d:\\codeGen") .setFileOverride(true); if (!serviceNameStartWithI) { config.setServiceName("I%sService"); } new AutoGenerator().setGlobalConfig(config) .setDataSource(dataSourceConfig) .setStrategy(strategyConfig) .setPackageInfo( new PackageConfig() .setParent(packageName) .setController("controller") .setEntity("entity") ).execute(); }
Example #5
Source File: GeneratorServiceEntity.java From paas with Apache License 2.0 | 5 votes |
private void generateByTables(boolean serviceNameStartWithI, String packageName, String... tableNames) { GlobalConfig config = new GlobalConfig(); String dbUrl = "jdbc:mysql://localhost:3306/test"; DataSourceConfig dataSourceConfig = new DataSourceConfig(); dataSourceConfig.setDbType(DbType.MYSQL) .setUrl(dbUrl) .setUsername("root") .setPassword("root") .setDriverName("com.mysql.jdbc.Driver"); StrategyConfig strategyConfig = new StrategyConfig(); strategyConfig .setCapitalMode(true) .setEntityLombokModel(false) .setDbColumnUnderline(true) .setNaming(NamingStrategy.underline_to_camel) .setInclude(tableNames); config.setActiveRecord(false) .setEnableCache(false) // XML 二级缓存 .setAuthor("jitwxs") .setOutputDir("d:\\codeGen") .setFileOverride(true); if (!serviceNameStartWithI) { config.setServiceName("%sService"); } new AutoGenerator().setGlobalConfig(config) .setDataSource(dataSourceConfig) .setStrategy(strategyConfig) .setPackageInfo( new PackageConfig() .setParent(packageName) .setController("controller") .setEntity("entity") ).execute(); }
Example #6
Source File: MybatisPlusGenerator.java From MI-S with MIT License | 5 votes |
/** * 数据源配置 **/ private DataSourceConfig setDataSourceConfig() { DataSourceConfig dsc = new DataSourceConfig(); dsc.setDbType(DbType.MYSQL); dsc.setDriverName(driverName); dsc.setUsername(username); dsc.setPassword(password); dsc.setUrl(url); return dsc; }
Example #7
Source File: EntityGenerator.java From MeetingFilm with Apache License 2.0 | 4 votes |
@Test public void entityGenerator() { AutoGenerator mpg = new AutoGenerator(); // 全局配置 GlobalConfig gc = new GlobalConfig(); gc.setOutputDir("F:\\workSpace\\meeting_workspace\\meeting_film\\meeting_film_backend\\guns\\guns-alipay\\src\\main\\java");//这里写你自己的java目录 gc.setFileOverride(true);//是否覆盖 gc.setActiveRecord(true); gc.setEnableCache(false);// XML 二级缓存 gc.setBaseResultMap(true);// XML ResultMap gc.setBaseColumnList(false);// XML columList gc.setAuthor("jiangzh"); 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("root"); dsc.setPassword(""); dsc.setUrl("jdbc:mysql://127.0.0.1:3306/guns_rest?autoReconnect=true&useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8"); mpg.setDataSource(dsc); // 策略配置 StrategyConfig strategy = new StrategyConfig(); //strategy.setTablePrefix(new String[]{"_"});// 此处可以修改为您的表前缀 strategy.setNaming(NamingStrategy.underline_to_camel);// 表名生成策略 strategy.setInclude(new String[]{"mooc_order_2017_t"}); mpg.setStrategy(strategy); // 包配置 PackageConfig pc = new PackageConfig(); pc.setParent(null); pc.setEntity("com.stylefeng.guns.rest.common.persistence.model"); pc.setMapper("com.stylefeng.guns.rest.common.persistence.dao"); pc.setXml("com.stylefeng.guns.rest.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")); }
Example #8
Source File: WebGeneratorConfig.java From MeetingFilm with Apache License 2.0 | 4 votes |
@Override protected void config() { /** * 数据库配置 */ dataSourceConfig.setDbType(DbType.MYSQL); dataSourceConfig.setDriverName("com.mysql.jdbc.Driver"); dataSourceConfig.setUsername(genQo.getUserName()); dataSourceConfig.setPassword(genQo.getPassword()); dataSourceConfig.setUrl(genQo.getUrl()); /** * 全局配置 */ globalConfig.setOutputDir(genQo.getProjectPath() + File.separator + "src" + File.separator + "main" + File.separator + "java"); globalConfig.setFileOverride(true); globalConfig.setEnableCache(false); globalConfig.setBaseResultMap(true); globalConfig.setBaseColumnList(true); globalConfig.setOpen(false); globalConfig.setAuthor(genQo.getAuthor()); contextConfig.setProPackage(genQo.getProjectPackage()); contextConfig.setCoreBasePackage(genQo.getCorePackage()); /** * 生成策略 */ if (genQo.getIgnoreTabelPrefix() != null) { strategyConfig.setTablePrefix(new String[]{genQo.getIgnoreTabelPrefix()}); } strategyConfig.setInclude(new String[]{genQo.getTableName()}); strategyConfig.setNaming(NamingStrategy.underline_to_camel); packageConfig.setParent(null); packageConfig.setEntity(genQo.getProjectPackage() + ".modular.system.model"); packageConfig.setMapper(genQo.getProjectPackage() + ".modular.system.dao"); packageConfig.setXml(genQo.getProjectPackage() + ".modular.system.dao.mapping"); /** * 业务代码配置 */ contextConfig.setBizChName(genQo.getBizName()); contextConfig.setModuleName(genQo.getModuleName()); contextConfig.setProjectPath(genQo.getProjectPath());//写自己项目的绝对路径 if(ToolUtil.isEmpty(genQo.getIgnoreTabelPrefix())){ String entityName = StrKit.toCamelCase(genQo.getTableName()); contextConfig.setEntityName(StrKit.firstCharToUpperCase(entityName)); contextConfig.setBizEnName(StrKit.firstCharToLowerCase(entityName)); }else{ String entiyName = StrKit.toCamelCase(StrKit.removePrefix(genQo.getTableName(), genQo.getIgnoreTabelPrefix())); contextConfig.setEntityName(StrKit.firstCharToUpperCase(entiyName)); contextConfig.setBizEnName(StrKit.firstCharToLowerCase(entiyName)); } sqlConfig.setParentMenuName(genQo.getParentMenuName());//这里写已有菜单的名称,当做父节点 /** * mybatis-plus 生成器开关 */ contextConfig.setEntitySwitch(genQo.getEntitySwitch()); contextConfig.setDaoSwitch(genQo.getDaoSwitch()); contextConfig.setServiceSwitch(genQo.getServiceSwitch()); /** * guns 生成器开关 */ contextConfig.setControllerSwitch(genQo.getControllerSwitch()); contextConfig.setIndexPageSwitch(genQo.getIndexPageSwitch()); contextConfig.setAddPageSwitch(genQo.getAddPageSwitch()); contextConfig.setEditPageSwitch(genQo.getEditPageSwitch()); contextConfig.setJsSwitch(genQo.getJsSwitch()); contextConfig.setInfoJsSwitch(genQo.getInfoJsSwitch()); contextConfig.setSqlSwitch(genQo.getSqlSwitch()); }
Example #9
Source File: EntityGenerator.java From MeetingFilm with Apache License 2.0 | 4 votes |
@Test public void entityGenerator() { AutoGenerator mpg = new AutoGenerator(); // 全局配置 GlobalConfig gc = new GlobalConfig(); gc.setOutputDir("F:\\workSpace\\meeting_workspace\\meeting_film\\meeting_film_backend\\guns\\guns-order\\src\\main\\java");//这里写你自己的java目录 gc.setFileOverride(true);//是否覆盖 gc.setActiveRecord(true); gc.setEnableCache(false);// XML 二级缓存 gc.setBaseResultMap(true);// XML ResultMap gc.setBaseColumnList(false);// XML columList gc.setAuthor("jiangzh"); 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("root"); dsc.setPassword(""); dsc.setUrl("jdbc:mysql://127.0.0.1:3306/guns_rest?autoReconnect=true&useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8"); mpg.setDataSource(dsc); // 策略配置 StrategyConfig strategy = new StrategyConfig(); //strategy.setTablePrefix(new String[]{"_"});// 此处可以修改为您的表前缀 strategy.setNaming(NamingStrategy.underline_to_camel);// 表名生成策略 strategy.setInclude(new String[]{"mooc_order_2017_t","mooc_order_2018_t"}); mpg.setStrategy(strategy); // 包配置 PackageConfig pc = new PackageConfig(); pc.setParent(null); pc.setEntity("com.stylefeng.guns.rest.common.persistence.model"); pc.setMapper("com.stylefeng.guns.rest.common.persistence.dao"); pc.setXml("com.stylefeng.guns.rest.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")); }
Example #10
Source File: EntityGenerator.java From MeetingFilm with Apache License 2.0 | 4 votes |
@Test public void entityGenerator() { AutoGenerator mpg = new AutoGenerator(); // 全局配置 GlobalConfig gc = new GlobalConfig(); gc.setOutputDir("F:\\workSpace\\meeting_workspace\\meeting_film\\meeting_film_backend\\guns\\guns-user\\src\\main\\java");//这里写你自己的java目录 gc.setFileOverride(true);//是否覆盖 gc.setActiveRecord(true); gc.setEnableCache(false);// XML 二级缓存 gc.setBaseResultMap(true);// XML ResultMap gc.setBaseColumnList(false);// XML columList gc.setAuthor("jiangzh"); 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("root"); dsc.setPassword(""); dsc.setUrl("jdbc:mysql://127.0.0.1:3306/guns_rest?autoReconnect=true&useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8"); mpg.setDataSource(dsc); // 策略配置 StrategyConfig strategy = new StrategyConfig(); //strategy.setTablePrefix(new String[]{"_"});// 此处可以修改为您的表前缀 strategy.setNaming(NamingStrategy.underline_to_camel);// 表名生成策略 strategy.setInclude(new String[]{"mooc_user_t"}); mpg.setStrategy(strategy); // 包配置 PackageConfig pc = new PackageConfig(); pc.setParent(null); pc.setEntity("com.stylefeng.guns.rest.common.persistence.model"); pc.setMapper("com.stylefeng.guns.rest.common.persistence.dao"); pc.setXml("com.stylefeng.guns.rest.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")); }
Example #11
Source File: EntityGenerator.java From MeetingFilm with Apache License 2.0 | 4 votes |
@Test public void entityGenerator() { AutoGenerator mpg = new AutoGenerator(); // 全局配置 GlobalConfig gc = new GlobalConfig(); gc.setOutputDir("D:\\tmp\\guns\\guns-rest\\src\\main\\java");//这里写你自己的java目录 gc.setFileOverride(true);//是否覆盖 gc.setActiveRecord(true); gc.setEnableCache(false);// XML 二级缓存 gc.setBaseResultMap(true);// XML ResultMap gc.setBaseColumnList(false);// XML columList gc.setAuthor("stylefeng"); 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("root"); dsc.setPassword("root"); dsc.setUrl("jdbc:mysql://127.0.0.1:3306/rest?characterEncoding=utf8"); mpg.setDataSource(dsc); // 策略配置 StrategyConfig strategy = new StrategyConfig(); //strategy.setTablePrefix(new String[]{"_"});// 此处可以修改为您的表前缀 strategy.setNaming(NamingStrategy.underline_to_camel);// 表名生成策略 strategy.setInclude(new String[]{"user"}); mpg.setStrategy(strategy); // 包配置 PackageConfig pc = new PackageConfig(); pc.setParent(null); pc.setEntity("com.stylefeng.guns.rest.persistence.model"); pc.setMapper("com.stylefeng.guns.rest.persistence.dao"); pc.setXml("com.stylefeng.guns.rest.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")); }
Example #12
Source File: EntityGenerator.java From MeetingFilm with Apache License 2.0 | 4 votes |
@Test public void entityGenerator() { AutoGenerator mpg = new AutoGenerator(); // 全局配置 GlobalConfig gc = new GlobalConfig(); gc.setOutputDir("G:\\BaiduNetdiskDownload\\应用Dubbo框架打造仿猫眼项目\\MeetingFilm\\guns-cinema\\src\\main\\java");//这里写你自己的java目录 gc.setFileOverride(true);//是否覆盖 gc.setActiveRecord(true); gc.setEnableCache(false);// XML 二级缓存 gc.setBaseResultMap(true);// XML ResultMap gc.setBaseColumnList(false);// XML columList gc.setAuthor("jiangzh"); 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("root"); dsc.setPassword("123456789qwER#"); dsc.setUrl("jdbc:mysql://119.3.214.253:3306/guns_rest?autoReconnect=true&useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8"); mpg.setDataSource(dsc); // 策略配置 StrategyConfig strategy = new StrategyConfig(); //strategy.setTablePrefix(new String[]{"_"});// 此处可以修改为您的表前缀 strategy.setNaming(NamingStrategy.underline_to_camel);// 表名生成策略 // strategy.setInclude(new String[]{"mooc_banner_t","mooc_cat_dict_t","mooc_area_dict_t","mooc_year_dict_t","mooc_film_t","mooc_film_info_t","mooc_actor_t"}); // strategy.setInclude(new String[]{"mooc_source_dict_t"}); strategy.setInclude(new String[]{"mooc_hall_film_info_t"}); mpg.setStrategy(strategy); // 包配置 PackageConfig pc = new PackageConfig(); pc.setParent(null); pc.setEntity("com.stylefeng.guns.rest.common.persistence.model"); pc.setMapper("com.stylefeng.guns.rest.common.persistence.dao"); pc.setXml("com.stylefeng.guns.rest.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")); }
Example #13
Source File: EntityGenerator.java From MeetingFilm with Apache License 2.0 | 4 votes |
@Test public void entityGenerator() { AutoGenerator mpg = new AutoGenerator(); // 全局配置 GlobalConfig gc = new GlobalConfig(); gc.setOutputDir("D:\\tmp\\guns\\guns-rest\\src\\main\\java");//这里写你自己的java目录 gc.setFileOverride(true);//是否覆盖 gc.setActiveRecord(true); gc.setEnableCache(false);// XML 二级缓存 gc.setBaseResultMap(true);// XML ResultMap gc.setBaseColumnList(false);// XML columList gc.setAuthor("stylefeng"); 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("root"); dsc.setPassword("root"); dsc.setUrl("jdbc:mysql://127.0.0.1:3306/rest?characterEncoding=utf8"); mpg.setDataSource(dsc); // 策略配置 StrategyConfig strategy = new StrategyConfig(); //strategy.setTablePrefix(new String[]{"_"});// 此处可以修改为您的表前缀 strategy.setNaming(NamingStrategy.underline_to_camel);// 表名生成策略 strategy.setInclude(new String[]{"user"}); mpg.setStrategy(strategy); // 包配置 PackageConfig pc = new PackageConfig(); pc.setParent(null); pc.setEntity("com.stylefeng.guns.rest.persistence.model"); pc.setMapper("com.stylefeng.guns.rest.persistence.dao"); pc.setXml("com.stylefeng.guns.rest.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")); }
Example #14
Source File: EntityGenerator.java From MeetingFilm with Apache License 2.0 | 4 votes |
@Test public void entityGenerator() { AutoGenerator mpg = new AutoGenerator(); // 全局配置 GlobalConfig gc = new GlobalConfig(); gc.setOutputDir("F:\\workSpace\\meeting_workspace\\meeting_film\\meeting_film_backend\\guns\\guns-film\\src\\main\\java");//这里写你自己的java目录 gc.setFileOverride(true);//是否覆盖 gc.setActiveRecord(true); gc.setEnableCache(false);// XML 二级缓存 gc.setBaseResultMap(true);// XML ResultMap gc.setBaseColumnList(false);// XML columList gc.setAuthor("jiangzh"); 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("root"); dsc.setPassword(""); dsc.setUrl("jdbc:mysql://127.0.0.1:3306/guns_rest?autoReconnect=true&useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8"); mpg.setDataSource(dsc); // 策略配置 StrategyConfig strategy = new StrategyConfig(); //strategy.setTablePrefix(new String[]{"_"});// 此处可以修改为您的表前缀 strategy.setNaming(NamingStrategy.underline_to_camel);// 表名生成策略 // strategy.setInclude(new String[]{"mooc_banner_t","mooc_cat_dict_t","mooc_area_dict_t","mooc_year_dict_t","mooc_film_t","mooc_film_info_t","mooc_actor_t"}); // strategy.setInclude(new String[]{"mooc_source_dict_t"}); strategy.setInclude(new String[]{"mooc_film_actor_t"}); mpg.setStrategy(strategy); // 包配置 PackageConfig pc = new PackageConfig(); pc.setParent(null); pc.setEntity("com.stylefeng.guns.rest.common.persistence.model"); pc.setMapper("com.stylefeng.guns.rest.common.persistence.dao"); pc.setXml("com.stylefeng.guns.rest.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")); }
Example #15
Source File: GenerateService.java From cola-cloud with MIT License | 4 votes |
@PostConstruct public void init(){ globalConfig= new GlobalConfig(); globalConfig.setFileOverride(true); globalConfig.setActiveRecord(false); // XML 二级缓存 globalConfig.setEnableCache(false); // XML ResultMap globalConfig.setBaseResultMap(false); // XML columList globalConfig.setBaseColumnList(false); // 自定义文件命名,注意 %s 会自动填充表实体属性! globalConfig.setMapperName("%sMapper"); globalConfig.setXmlName("%sMapper"); globalConfig.setServiceName("%sService"); globalConfig.setServiceImplName("%sServiceImpl"); globalConfig.setControllerName("%sController"); // 数据源配置 dataSourceConfig = new DataSourceConfig(); dataSourceConfig.setDbType(DbType.MYSQL); dataSourceConfig.setTypeConvert(new MySqlTypeConvert(){ // 自定义数据库表字段类型转换【可选】 @Override public DbColumnType processTypeConvert(String fieldType) { System.out.println("转换类型:" + fieldType); // 注意!!processTypeConvert 存在默认类型转换,如果不是你要的效果请自定义返回、非如下直接返回。 return super.processTypeConvert(fieldType); } }); dataSourceConfig.setDriverName(dataSourceProperties.getDriverClassName()); dataSourceConfig.setUsername(dataSourceProperties.getUsername()); dataSourceConfig.setPassword(dataSourceProperties.getPassword()); dataSourceConfig.setUrl(dataSourceProperties.getUrl()); // 策略配置 strategyConfig = new StrategyConfig(); // 表名生成策略 strategyConfig.setNaming(NamingStrategy.underline_to_camel); // 需要生成的表 // 自定义 service 父类 strategyConfig.setSuperServiceClass("com.honvay.cola.cloud.framework.base.service.BaseService"); // 自定义 service 实现类父类 strategyConfig.setSuperServiceImplClass("com.honvay.cola.cloud.framework.base.service.impl.BaseServiceImpl"); // 自定义 controller 父类 strategyConfig.setSuperControllerClass("com.honvay.cola.cloud.framework.base.controller.BaseController"); strategyConfig.setEntityLombokModel(true); strategyConfig.setRestControllerStyle(true); strategyConfig.setEntityBuilderModel(true); packageConfig = new PackageConfig(); packageConfig.setController("controller"); packageConfig.setEntity("entity"); packageConfig.setMapper("mapper"); packageConfig.setService("service"); packageConfig.setServiceImpl("service.impl"); entityNameRewriter = new EntityNameRewriter(); }
Example #16
Source File: PigResourcesGenerator.java From pig with MIT License | 4 votes |
public static void main(String[] args) { String outputDir = "/Users/lengleng/work/temp"; final String viewOutputDir = outputDir + "/view/"; AutoGenerator mpg = new AutoGenerator(); // 全局配置 GlobalConfig gc = new GlobalConfig(); gc.setOutputDir(outputDir); gc.setFileOverride(true); gc.setActiveRecord(true); // XML 二级缓存 gc.setEnableCache(false); // XML ResultMap gc.setBaseResultMap(true); // XML columList gc.setBaseColumnList(true); gc.setAuthor("lengleng"); mpg.setGlobalConfig(gc); // 数据源配置 DataSourceConfig dsc = new DataSourceConfig(); dsc.setDbType(DbType.MYSQL); dsc.setDriverName("com.mysql.jdbc.Driver"); dsc.setUsername("root"); dsc.setPassword("lengleng"); dsc.setUrl("jdbc:mysql://139.224.200.249:3309/pig?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false"); mpg.setDataSource(dsc); // 策略配置 StrategyConfig strategy = new StrategyConfig(); // strategy.setCapitalMode(true);// 全局大写命名 ORACLE 注意 strategy.setSuperControllerClass("com.github.pig.common.web.BaseController"); // 表名生成策略 strategy.setNaming(NamingStrategy.underline_to_camel); mpg.setStrategy(strategy); // 包配置 PackageConfig pc = new PackageConfig(); pc.setParent("com.github.pig.admin"); pc.setController("controller"); mpg.setPackageInfo(pc); // 注入自定义配置,可以在 VM 中使用 cfg.abc 设置的值 InjectionConfig cfg = new InjectionConfig() { @Override public void initMap() { } }; // 生成的模版路径,不存在时需要先新建 File viewDir = new File(viewOutputDir); if (!viewDir.exists()) { viewDir.mkdirs(); } List<FileOutConfig> focList = new ArrayList<FileOutConfig>(); focList.add(new FileOutConfig("/templates/listvue.vue.vm") { @Override public String outputFile(TableInfo tableInfo) { return getGeneratorViewPath(viewOutputDir, tableInfo, ".vue"); } }); cfg.setFileOutConfigList(focList); mpg.setCfg(cfg); //生成controller相关 mpg.execute(); }