Java Code Examples for com.baomidou.mybatisplus.generator.config.DataSourceConfig#setDriverName()

The following examples show how to use com.baomidou.mybatisplus.generator.config.DataSourceConfig#setDriverName() . 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: MyBatisPlusGenerator.java    From SpringBootLearn with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
    // 代码生成器
    AutoGenerator mpg = new AutoGenerator();

    //1. 全局配置
    GlobalConfig gc = new GlobalConfig();
    gc.setOutputDir("/Volumes/李浩东的移动硬盘/LiHaodong/springboot-security/src/main/java");
    gc.setOpen(false);
    gc.setFileOverride(true);
    gc.setBaseResultMap(true);//生成基本的resultMap
    gc.setBaseColumnList(false);//生成基本的SQL片段
    gc.setAuthor("lihaodong");// 作者
    mpg.setGlobalConfig(gc);

    //2. 数据源配置
    DataSourceConfig dsc = new DataSourceConfig();
    dsc.setDbType(DbType.MYSQL);
    dsc.setDriverName("com.mysql.jdbc.Driver");
    dsc.setUsername("root");
    dsc.setPassword("root");
    dsc.setUrl("jdbc:mysql://127.0.0.1:3306/test");
    mpg.setDataSource(dsc);

    //3. 策略配置globalConfiguration中
    StrategyConfig strategy = new StrategyConfig();
    strategy.setTablePrefix("");// 此处可以修改为您的表前缀
    strategy.setNaming(NamingStrategy.underline_to_camel);// 表名生成策略
    strategy.setSuperEntityClass("com.li.springbootsecurity.model");
    strategy.setInclude("role"); // 需要生成的表
    strategy.setEntityLombokModel(true);
    strategy.setRestControllerStyle(true);
    strategy.setControllerMappingHyphenStyle(true);

    mpg.setStrategy(strategy);

    //4. 包名策略配置
    PackageConfig pc = new PackageConfig();
    pc.setParent("com.li.springbootsecurity");
    pc.setEntity("model");
    mpg.setPackageInfo(pc);

    // 执行生成
    mpg.execute();

}
 
Example 2
Source File: EntityGenerator.java    From MeetingFilm with Apache License 2.0 4 votes vote down vote up
@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 3
Source File: EntityGenerator.java    From MeetingFilm with Apache License 2.0 4 votes vote down vote up
@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 4
Source File: EntityGenerator.java    From MeetingFilm with Apache License 2.0 4 votes vote down vote up
@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 5
Source File: EntityGenerator.java    From MeetingFilm with Apache License 2.0 4 votes vote down vote up
@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 6
Source File: EntityGenerator.java    From MeetingFilm with Apache License 2.0 4 votes vote down vote up
@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 7
Source File: EntityGenerator.java    From MeetingFilm with Apache License 2.0 4 votes vote down vote up
@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 8
Source File: EntityGenerator.java    From MeetingFilm with Apache License 2.0 4 votes vote down vote up
@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 9
Source File: CodeGenerator.java    From My-Blog-layui with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
        // 代码生成器
        AutoGenerator mpg = new AutoGenerator();

        // 全局配置
        GlobalConfig gc = new GlobalConfig();
        // 当前工程路径
        String projectPath = System.getProperty("user.dir");
        gc.setOutputDir(projectPath + outPutDir);
        gc.setDateType(DateType.ONLY_DATE);
        gc.setAuthor("zhulin");
        gc.setOpen(false);
        gc.setBaseResultMap(true);
        gc.setBaseColumnList(true);
        // 覆盖生成的文件
        gc.setFileOverride(true);
        gc.setServiceName("%sService");
        mpg.setGlobalConfig(gc);

        // 数据源配置
        DataSourceConfig dsc = new DataSourceConfig();
        dsc.setUrl(dataUrl);
        dsc.setDriverName(driverName);
        dsc.setUsername(dataName);
        dsc.setPassword(dataPwd);
        mpg.setDataSource(dsc);

        // 包配置
        PackageConfig pc = new PackageConfig();
        pc.setParent(parentPackage)
                .setMapper(mapperName)
                .setEntity(pojoName)
                .setService(serviceName)
                .setController(controllerName)
                .setServiceImpl(implName)
                .setXml(xmlName);
        mpg.setPackageInfo(pc);

/*        // 自定义配置
        InjectionConfig cfg = new InjectionConfig() {
            @Override
            public void initMap() {
                // to do nothing
            }
        };
        // 自定义输出配置
        List<FileOutConfig> focList = new ArrayList<>();
        focList.add(new FileOutConfig() {
            @Override
            public String outputFile(TableInfo tableInfo) {
                // 自定义输出文件名 , 如果你 Entity 设置了前后缀、此处注意 xml 的名称会跟着发生变化!!
                return projectPath + "/src/main/resources/mapping/"
                        + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
            }
        });
        cfg.setFileOutConfigList(focList);
        mpg.setCfg(cfg);*/


        // 策略配置
        StrategyConfig strategy = new StrategyConfig();
        strategy.setNaming(NamingStrategy.underline_to_camel);
        strategy.setColumnNaming(NamingStrategy.underline_to_camel);
        strategy.setEntityTableFieldAnnotationEnable(true);
        strategy.setEntityLombokModel(true);
        strategy.setInclude(scanner("表名,多个英文逗号分割").split(","));
        //默认生成全部
/*        strategy.setExclude(null);*/
        strategy.setControllerMappingHyphenStyle(true);
        mpg.setStrategy(strategy);
        mpg.execute();
    }
 
Example 10
Source File: CodeGenerator.java    From springboot-restful-starter with MIT License 4 votes vote down vote up
public static void main(String[] args) {
    // 代码生成器
    AutoGenerator mpg = new AutoGenerator();

    // 全局配置
    GlobalConfig gc = new GlobalConfig();
    String projectPath = System.getProperty("user.dir");
    gc.setOutputDir(projectPath + "/src/main/java");
    gc.setAuthor(AUTHOR);
    gc.setOpen(false);
    mpg.setGlobalConfig(gc);

    // 数据源配置
    DataSourceConfig dsc = new DataSourceConfig();
    dsc.setUrl("jdbc:mysql://localhost:3306/"+DATABASE+"?serverTimezone=Asia/Shanghai&useUnicode=true&useSSL=false&characterEncoding=utf8");
    // dsc.setSchemaName("public");
    dsc.setDriverName("com.mysql.cj.jdbc.Driver");
    dsc.setUsername(DATABASE_USERNAME);
    dsc.setPassword(DATABASE_PASSWORD);
    mpg.setDataSource(dsc);

    // 包配置
    PackageConfig pc = new PackageConfig();
    pc.setModuleName(scanner("模块名"));
    pc.setParent(PROJECT);
    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 + "/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(PROJECT + ".base.BaseEntity");     // 自定义实体类继承
    strategy.setEntityLombokModel(true);
    strategy.setRestControllerStyle(true);
    //strategy.setSuperControllerClass(PROJECT + ".base.BaseController");     // 自定义控制器继承
    strategy.setInclude(scanner("表名"));
    strategy.setSuperEntityColumns("id");
    strategy.setControllerMappingHyphenStyle(true);
    strategy.setTablePrefix(pc.getModuleName() + "_");
    mpg.setStrategy(strategy);
    mpg.setTemplateEngine(new FreemarkerTemplateEngine());
    mpg.execute();
}
 
Example 11
Source File: GeneratorService.java    From spring-cloud-shop with MIT License 4 votes vote down vote up
/**
 * 自动生成代码
 *
 * @param tableSchema 数据库空间
 * @param tableName   表名
 */
public Response generator(String tableSchema, String tableName) {

    // 代码生成器
    AutoGenerator mpg = new AutoGenerator();

    // 全局配置
    GlobalConfig gc = new GlobalConfig();
    String projectPath = System.getProperty("user.dir");
    gc.setOutputDir(projectPath + "/shop/src/main/java");
    gc.setAuthor(System.getProperty("user.name"));
    gc.setOpen(false);
    mpg.setGlobalConfig(gc);

    // 数据源配置
    DataSourceConfig dsc = new DataSourceConfig();
    dsc.setUrl(MessageFormat.format("jdbc:mysql://localhost:3306/{0}?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=UTF-8&useSSL=false", tableSchema));
    dsc.setDriverName("com.mysql.cj.jdbc.Driver");
    dsc.setUsername("root");
    dsc.setPassword("root");
    mpg.setDataSource(dsc);

    // 包配置
    PackageConfig pc = new PackageConfig();
    pc.setModuleName("shop");
    pc.setParent("quick.pager.shop");
    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 + "/shop/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("quick.pager.shop.model.Model");
    strategy.setEntityLombokModel(true);
    strategy.setInclude(tableName);
    strategy.setSuperEntityColumns("id");
    strategy.setControllerMappingHyphenStyle(true);
    strategy.setTablePrefix(pc.getModuleName() + "_");
    mpg.setStrategy(strategy);
    mpg.setTemplateEngine(new FreemarkerTemplateEngine());
    mpg.execute();

    return new Response();
}
 
Example 12
Source File: CodeGeneration.java    From poseidon with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
	AutoGenerator mpg = new AutoGenerator();
	// 全局配置
	GlobalConfig gc = new GlobalConfig();
	gc.setOutputDir(
			"/media/code/program/java/poseidon/poseidon/psd-web-view/src/main/java");
	gc.setFileOverride(true);
	gc.setActiveRecord(false);// 不需要ActiveRecord特性的请改为false
	gc.setEnableCache(false);// XML 二级缓存
	gc.setBaseResultMap(true);// XML ResultMap
	gc.setBaseColumnList(false);// XML columList
	gc.setAuthor("yoke");// 作者

	// 自定义文件命名,注意 %s 会自动填充表实体属性!
	gc.setControllerName("%sController");
	gc.setServiceName("%sService");
	gc.setServiceImplName("%sServiceImpl");
	gc.setMapperName("%sMapper");
	gc.setXmlName("%sMapper");
	mpg.setGlobalConfig(gc);

	// 数据源配置
	DataSourceConfig dsc = new DataSourceConfig();
	dsc.setDbType(DbType.MYSQL);
	dsc.setDriverName("com.mysql.cj.jdbc.Driver");
	dsc.setUsername("root");
	dsc.setPassword("FJEOIRFWQ132EW");
	dsc.setUrl(
			"jdbc:mysql://www.test.com:13306/poseidon?useUnicode=true&characterEncoding=utf-8&useSSL=false");
	mpg.setDataSource(dsc);

	// 策略配置
	StrategyConfig strategy = new StrategyConfig();
	strategy.setTablePrefix("db_");// 此处可以修改为您的表前缀
	strategy.setNaming(NamingStrategy.underline_to_camel);// 表名生成策略
	strategy.setInclude("db_item_attribute_name", "db_item_attribute_value",
			"db_item_sku");
	strategy.setSuperServiceClass(null);
	strategy.setSuperServiceImplClass(null);
	strategy.setSuperMapperClass(null);
	mpg.setStrategy(strategy);

	// 包配置
	PackageConfig pc = new PackageConfig();
	pc.setParent("com.yoke.poseidon.web.itemShow");
	pc.setController("web");
	pc.setService("service");
	pc.setServiceImpl("serviceImpl");
	pc.setMapper("mapper");
	pc.setEntity("entity");
	pc.setXml("mapper");
	mpg.setPackageInfo(pc);
	// 执行生成
	mpg.execute();

}