Java Code Examples for com.baomidou.mybatisplus.generator.config.rules.NamingStrategy

The following examples show how to use com.baomidou.mybatisplus.generator.config.rules.NamingStrategy. These examples are extracted from open source projects. 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 Project: pre   Author: LiHaodong888   File: CodeGenUtil.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * 策略配置
 *
 * @param tableNames 表名
 * @return StrategyConfig
 */
private StrategyConfig getStrategyConfig(String... tableNames) {

    return new StrategyConfig()
            .setEntityLombokModel(true)
            //表名生成策略  下划线转驼峰
            .setNaming(NamingStrategy.underline_to_camel)
            .setColumnNaming(NamingStrategy.underline_to_camel)
            //需要生成的的表名,多个表名传数组
            .setInclude(tableNames)
            .setRestControllerStyle(true)
            .setControllerMappingHyphenStyle(true);
}
 
Example #2
Source Project: express-ssm   Author: jitwxs   File: GeneratorServiceEntity.java    License: Apache License 2.0 5 votes vote down vote up
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 Project: blog-sample   Author: jitwxs   File: GeneratorServiceEntity.java    License: Apache License 2.0 5 votes vote down vote up
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 Project: blog-sample   Author: jitwxs   File: GeneratorServiceEntity.java    License: Apache License 2.0 5 votes vote down vote up
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 Project: paas   Author: jitwxs   File: GeneratorServiceEntity.java    License: Apache License 2.0 5 votes vote down vote up
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 Project: MI-S   Author: MIYAOW   File: MybatisPlusGenerator.java    License: MIT License 5 votes vote down vote up
/**
 * 生成策略配置
 **/
private StrategyConfig setStrategyConfig() {
    StrategyConfig strategy = new StrategyConfig();
    // strategy.setTablePrefix(new String[]{""});// 此处可以修改为您的表前缀
    strategy.setInclude(tables); // 需要生成的表
    // strategy.setExclude(new String[]{"test"}); // 排除生成的表
    strategy.setNaming(NamingStrategy.underline_to_camel);// 表名生成策略
    // 字段名生成策略
    // strategy.setFieldNaming(NamingStrategy.underline_to_camel);
    // 自定义实体父类
    //  strategy.setSuperEntityClass("com.mi.common.model.BaseModel");
    // 自定义实体,公共字段
    // strategy.setSuperEntityColumns(new String[] { "test_id", "age" });
    // 自定义 mapper 父类
    // strategy.setSuperMapperClass("com.baomidou.demo.TestMapper");
    // 自定义 service 父类
    // strategy.setSuperServiceClass("com.baomidou.demo.TestService");
    // 自定义 service 实现类父类
    // strategy.setSuperServiceImplClass("com.baomidou.demo.TestServiceImpl");
    // 自定义 controller 父类
    // 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);
    strategy.setCapitalMode(true);
    return strategy;
}
 
Example #7
Source Project: SpringBootLearn   Author: LiHaodong888   File: MyBatisPlusGenerator.java    License: 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 #8
Source Project: supplierShop   Author: guchengwuyue   File: CodeGenerator.java    License: MIT License 4 votes vote down vote up
public static String underlineToCamel(String underline){
    if (StringUtils.isNotBlank(underline)){
        return NamingStrategy.underlineToCamel(underline);
    }
    return null;
}
 
Example #9
Source Project: supplierShop   Author: guchengwuyue   File: CodeGenerator.java    License: MIT License 4 votes vote down vote up
public static String underlineToPascal(String underline){
    if (StringUtils.isNotBlank(underline)){
        return NamingStrategy.capitalFirst(NamingStrategy.underlineToCamel(underline));
    }
    return null;
}
 
Example #10
Source Project: spring-boot-shiro   Author: MRLEILOVE   File: CodeGeneratorUtils.java    License: 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 + "/src/main/java");
        gc.setAuthor(AUTHOR);
        gc.setOpen(false);
//        gc.setSwagger2(true);
        mpg.setGlobalConfig(gc);

        // 数据源配置
        DataSourceConfig dsc = new DataSourceConfig();
        dsc.setUrl(String.format("jdbc:mysql://%s:3306/%s?useUnicode=true&useSSL=false&characterEncoding=utf8&serverTimezone=UTC", HOST, DATABASE_NAME));
        // dsc.setSchemaName("public");
        dsc.setDriverName(DRIVER_CLASS_NAME);
        dsc.setUsername(DATABASE_USERNAME);
        dsc.setPassword(DATABASE_PASSWORD);
        mpg.setDataSource(dsc);

        // 包配置
        PackageConfig pc = new PackageConfig();
        pc.setModuleName(scanner("模块名"));
        pc.setParent(PARENT_PACKAGE);
        mpg.setPackageInfo(pc);

        // 自定义配置
        InjectionConfig cfg = new InjectionConfig() {
            @Override
            public void initMap() {
                // to do nothing
            }
        };

        // 如果模板引擎是 freemarker
        String templatePath = "/templates/mapper.xml.ftl";
        // 如果模板引擎是 velocity
        // String templatePath = "/templates/mapper.xml.vm";

        // 自定义输出配置
        List<FileOutConfig> focList = new ArrayList<>();
        // 自定义配置会被优先输出
        focList.add(new FileOutConfig(templatePath) {
            @Override
            public String outputFile(TableInfo tableInfo) {
                // 自定义输出文件名 , 如果你 Entity 设置了前后缀、此处注意 xml 的名称会跟着发生变化!!
                return projectPath + "/src/main/resources/mapper/" + pc.getModuleName()
                        + "/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
            }
        });
        /*
        cfg.setFileCreate(new IFileCreate() {
            @Override
            public boolean isCreate(ConfigBuilder configBuilder, FileType fileType, String filePath) {
                // 判断自定义文件夹是否需要创建
                checkDir("调用默认方法创建的目录");
                return false;
            }
        });
        */
        cfg.setFileOutConfigList(focList);
        mpg.setCfg(cfg);

        // 配置模板
        TemplateConfig templateConfig = new TemplateConfig();

        // 配置自定义输出模板
        //指定自定义模板路径,注意不要带上.ftl/.vm, 会根据使用的模板引擎自动识别
        // templateConfig.setEntity("templates/entity2.java");
        // templateConfig.setService();
        // templateConfig.setController();

        templateConfig.setXml(null);
        mpg.setTemplate(templateConfig);

        // 策略配置
        StrategyConfig strategy = new StrategyConfig();
        strategy.setNaming(NamingStrategy.underline_to_camel);
        strategy.setColumnNaming(NamingStrategy.underline_to_camel);
//        strategy.setSuperEntityClass("com.baomidou.ant.common.BaseEntity");
        strategy.setEntityLombokModel(true);
        strategy.setRestControllerStyle(true);
//        strategy.setSuperControllerClass("com.baomidou.ant.common.BaseController");
        strategy.setInclude(scanner("表名,多个英文逗号分割").split(","));
        strategy.setSuperEntityColumns("id");
        strategy.setControllerMappingHyphenStyle(true);
        strategy.setTablePrefix(pc.getModuleName() + "_");
        mpg.setStrategy(strategy);
        mpg.setTemplateEngine(new FreemarkerTemplateEngine());
        mpg.execute();
    }
 
Example #11
Source Project: spring-boot-demo   Author: smltq   File: MysqlGenerator.java    License: MIT License 4 votes vote down vote up
/**
 * RUN THIS
 */
public static void main(String[] args) {
    // 代码生成器
    AutoGenerator mpg = new AutoGenerator();

    // 全局配置
    GlobalConfig gc = new GlobalConfig();
    final String projectPath = System.getProperty("user.dir");
    gc.setOutputDir(projectPath + "/mybatis-plus-generator/merchantplatform/src/main/java");
    gc.setAuthor("bbx");
    gc.setOpen(false);
    mpg.setGlobalConfig(gc);

    // 数据源配置
    DataSourceConfig dsc = new DataSourceConfig();
    dsc.setUrl("jdbc:mysql://bbx-testdb-out.mysql.rds.aliyuncs.com:3306/bbx_test?useSSL=false&useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&serverTimezone=GMT%2B8");
    // dsc.setSchemaName("public");
    dsc.setDriverName("com.mysql.cj.jdbc.Driver");
    dsc.setUsername("bbx_root");
    dsc.setPassword("LHBbx#[email protected]");
    mpg.setDataSource(dsc);

    // 包配置
    final PackageConfig pc = new PackageConfig();
    pc.setModuleName(scanner("模块名"));
    pc.setParent("com.bbx.merchantplatform");
    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-generator/merchantplatform/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.bbx.merchantplatform.common.base.BaseEntity");
    strategy.setEntityLombokModel(true);
    strategy.setSuperControllerClass("com.bbx.merchantplatform.common.base.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();
}
 
Example #12
Source Project: MeetingFilm   Author: daydreamdev   File: EntityGenerator.java    License: 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 #13
Source Project: MeetingFilm   Author: daydreamdev   File: WebGeneratorConfig.java    License: Apache License 2.0 4 votes vote down vote up
@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 #14
Source Project: MeetingFilm   Author: daydreamdev   File: GunsGeneratorConfig.java    License: Apache License 2.0 4 votes vote down vote up
protected void strategyConfig() {
    strategyConfig.setTablePrefix(new String[]{"sys_"});// 此处可以修改为您的表前缀
    strategyConfig.setNaming(NamingStrategy.underline_to_camel);
}
 
Example #15
Source Project: MeetingFilm   Author: daydreamdev   File: EntityGenerator.java    License: 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 #16
Source Project: MeetingFilm   Author: daydreamdev   File: EntityGenerator.java    License: 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 #17
Source Project: MeetingFilm   Author: daydreamdev   File: EntityGenerator.java    License: 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 #18
Source Project: MeetingFilm   Author: daydreamdev   File: EntityGenerator.java    License: 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 #19
Source Project: MeetingFilm   Author: daydreamdev   File: EntityGenerator.java    License: 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 #20
Source Project: MeetingFilm   Author: daydreamdev   File: EntityGenerator.java    License: 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 #21
Source Project: My-Blog-layui   Author: ZHENFENG13   File: CodeGenerator.java    License: 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 #22
Source Project: spring-boot-plus   Author: geekidea   File: SpringBootPlusGenerator.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 生成代码
 * @param args
 */
public static void main(String[] args) {
    GeneratorProperties generatorProperties = new GeneratorProperties();

    // 设置基本信息
    generatorProperties
            .setMavenModuleName("example")
            .setParentPackage("com.example")
            .setModuleName("foobar")
            .setAuthor("geekidea")
            .setFileOverride(true);

    // 设置表信息
    generatorProperties.addTable("foo_bar","id");
    // 设置表前缀
    // generatorProperties.setTablePrefix(Arrays.asList("tb_"));

    // 数据源配置
    generatorProperties.getDataSourceConfig()
            .setDbType(DbType.MYSQL)
            .setUsername("root")
            .setPassword("root")
            .setDriverName("com.mysql.jdbc.Driver")
            .setUrl("jdbc:mysql://localhost:3306/spring_boot_plus?useUnicode=true&characterEncoding=UTF-8&useSSL=false");

    // 生成配置
    generatorProperties.getGeneratorConfig()
            .setGeneratorStrategy(GeneratorStrategy.SINGLE)
            .setGeneratorEntity(true)
            .setGeneratorController(true)
            .setGeneratorService(true)
            .setGeneratorServiceImpl(true)
            .setGeneratorMapper(true)
            .setGeneratorMapperXml(true)
            .setGeneratorPageParam(true)
            .setGeneratorQueryVo(true)
            .setRequiresPermissions(false)
            .setPageListOrder(true)
            .setParamValidation(true)
            .setSwaggerTags(true)
            .setOperationLog(true);

    // 全局配置
    generatorProperties.getMybatisPlusGeneratorConfig().getGlobalConfig()
            .setOpen(true)
            .setSwagger2(true)
            .setIdType(IdType.AUTO)
            .setDateType(DateType.ONLY_DATE);

    // 策略配置
    generatorProperties.getMybatisPlusGeneratorConfig().getStrategyConfig()
            .setNaming(NamingStrategy.underline_to_camel)
            .setColumnNaming(NamingStrategy.underline_to_camel)
            .setEntityLombokModel(true)
            .setRestControllerStyle(true)
            .setControllerMappingHyphenStyle(true)
            .setVersionFieldName(GeneratorConstant.VERSION)
            .setLogicDeleteFieldName(GeneratorConstant.DELETED);

    // 生成代码
    CodeGenerator codeGenerator = new CodeGenerator();
    codeGenerator.generator(generatorProperties);

}
 
Example #23
Source Project: kvf-admin   Author: kalvinGit   File: CodeGenerator2.java    License: 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");
        System.out.println("projectPath = " + projectPath);
        gc.setOutputDir(projectPath + "/src/main/java");
        gc.setAuthor("Kalvin");
        gc.setOpen(false);
        gc.setIdType(IdType.AUTO);
        // gc.setSwagger2(true); 实体属性 Swagger2 注解
        mpg.setGlobalConfig(gc);

        // 数据源配置
        DataSourceConfig dsc = new DataSourceConfig();
        dsc.setUrl("jdbc:mysql://localhost:3306/activiti_k?useUnicode=true&useSSL=false&characterEncoding=utf8&serverTimezone=GMT%2B8");
        // dsc.setSchemaName("public");
        dsc.setDriverName("com.mysql.jdbc.Driver");
        dsc.setUsername("root");
        dsc.setPassword("root");
        mpg.setDataSource(dsc);

        // 包配置
        PackageConfig pc = new PackageConfig();
        pc.setModuleName(scanner("模块名"));
        pc.setParent("com.kalvin");
        mpg.setPackageInfo(pc);

        // 自定义配置
        InjectionConfig cfg = new InjectionConfig() {
            @Override
            public void initMap() {
                // to do nothing
            }
        };

        // 如果模板引擎是 freemarker
//        String templatePath = "/templates/mapper.xml.ftl";
        // 如果模板引擎是 velocity
         String templatePath = "/templates/mapper.xml.vm";

        // 自定义输出配置
        List<FileOutConfig> focList = new ArrayList<>();
        // 自定义配置会被优先输出
        focList.add(new FileOutConfig(templatePath) {
            @Override
            public String outputFile(TableInfo tableInfo) {
                // 自定义输出文件名 , 如果你 Entity 设置了前后缀、此处注意 xml 的名称会跟着发生变化!!
                return projectPath + "/src/main/resources/mapper/" + pc.getModuleName()
                        + "/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
            }
        });
        /*
        cfg.setFileCreate(new IFileCreate() {
            @Override
            public boolean isCreate(ConfigBuilder configBuilder, FileType fileType, String filePath) {
                // 判断自定义文件夹是否需要创建
                checkDir("调用默认方法创建的目录");
                return false;
            }
        });
        */
        cfg.setFileOutConfigList(focList);
        mpg.setCfg(cfg);

        // 配置模板
        TemplateConfig templateConfig = new TemplateConfig();

        // 配置自定义输出模板
        //指定自定义模板路径,注意不要带上.ftl/.vm, 会根据使用的模板引擎自动识别
        // templateConfig.setEntity("templates/entity2.java");
        // templateConfig.setService();
        // templateConfig.setController();

        templateConfig.setXml(null);
        mpg.setTemplate(templateConfig);

        // 策略配置
        StrategyConfig strategy = new StrategyConfig();
        strategy.setNaming(NamingStrategy.underline_to_camel);
        strategy.setColumnNaming(NamingStrategy.underline_to_camel);
        strategy.setSuperEntityClass("com.kalvin.kvf.common.entity.BaseEntity");
        strategy.setEntityLombokModel(true);
        strategy.setRestControllerStyle(true);
        strategy.setSuperControllerClass("com.kalvin.kvf.common.controller.BaseController");
        strategy.setInclude(scanner("表名,多个英文逗号分割").split(","));
        strategy.setSuperEntityColumns("id");
        strategy.setControllerMappingHyphenStyle(true);
        strategy.setTablePrefix(pc.getModuleName() + "_");
        mpg.setStrategy(strategy);
//        mpg.setTemplateEngine(new FreemarkerTemplateEngine());
        mpg.execute();
    }
 
Example #24
Source Project: kvf-admin   Author: kalvinGit   File: CodeGenerator.java    License: MIT License 4 votes vote down vote up
private static void generateByTables(boolean serviceNameStartWithI, String packageName, String... tableNames) {
        GlobalConfig config = new GlobalConfig();
        DataSourceConfig dataSourceConfig = new DataSourceConfig();
        dataSourceConfig.setDbType(DbType.MYSQL).setUrl(dbUrl).setUsername(dbUsername).setPassword(dbPassword)
                .setDriverName("com.mysql.jdbc.Driver").setTypeConvert((globalConfig, s) -> {
            if (s.contains("tinyint(1)")) { // 自定义数据库表字段类型转换
                return DbColumnType.INTEGER;
            }
            return new MySqlTypeConvert().processTypeConvert(globalConfig, s);
        });
        StrategyConfig strategyConfig = new StrategyConfig();
        strategyConfig
                .setCapitalMode(true)
                .setEntityLombokModel(true)
//                .setDbColumnUnderline(true)
                .setTablePrefix(tablePrefix)
                .setNaming(NamingStrategy.underline_to_camel)
                .setInclude(tableNames)//修改替换成你需要的表名,多个表名传数组
                .setRestControllerStyle(true)
                .setSuperEntityClass("com.kalvin.kvf.common.entity.BaseEntity")
                .setSuperControllerClass("com.kalvin.kvf.common.controller.BaseController");

        config.setActiveRecord(false)
                .setAuthor(author)
                .setOutputDir(outputDir)
                .setFileOverride(true)
                .setEnableCache(false)
                .setBaseResultMap(true)
                .setBaseColumnList(true);
        TemplateConfig tc = new TemplateConfig();
        if (!serviceNameStartWithI) {
            config.setServiceName("%sService");
            config.setMapperName("%sMapper");
        }
        new AutoGenerator().setGlobalConfig(config)
                .setTemplate(tc)
                .setDataSource(dataSourceConfig)
                .setStrategy(strategyConfig)
                .setPackageInfo(
                        new PackageConfig()
                                .setParent(packageName)
                                .setEntity("entity.sys")
                                .setMapper("mapper.sys")
                                .setController("controller.sys")
                                .setService("service.sys")
                                .setServiceImpl("service.sys")
                                .setXml("xml.sys")
                ).execute();
    }
 
Example #25
Source Project: Nickle-Scheduler   Author: NickleHuang   File: Generator.java    License: 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.setBaseResultMap(true);
        gc.setBaseColumnList(true);
        String projectPath = System.getProperty("user.dir")+"/Scheduler-Server";
        gc.setOutputDir(projectPath + "/src/main/java");
        gc.setAuthor("nickle");
        gc.setOpen(false);
        // gc.setSwagger2(true); 实体属性 Swagger2 注解
        mpg.setGlobalConfig(gc);

        // 数据源配置
        DataSourceConfig dsc = new DataSourceConfig();
        dsc.setUrl("jdbc:mysql://10.155.10.38:4502/nickle-scheduler?Unicode=true&characterEncoding=UTF-8");
        // dsc.setSchemaName("public");
        dsc.setDriverName("com.mysql.cj.jdbc.Driver");
        dsc.setUsername("shark_dev");
        dsc.setPassword("shark_dev");
        mpg.setDataSource(dsc);

        // 包配置
        PackageConfig pc = new PackageConfig();
        pc.setModuleName("server");
        pc.setParent("nickle.scheduler");
        mpg.setPackageInfo(pc);

        // 自定义配置
        InjectionConfig cfg = new InjectionConfig() {
            @Override
            public void initMap() {
                // to do nothing
            }
        };

        // 如果模板引擎是 freemarker
        //String templatePath = "/templates/mapper.xml.ftl";
        // 如果模板引擎是 velocity
        // String templatePath = "/templates/mapper.xml.vm";

        // 自定义输出配置
        List<FileOutConfig> focList = new ArrayList<>();
        // 自定义配置会被优先输出
        focList.add(new FileOutConfig() {
            @Override
            public String outputFile(TableInfo tableInfo) {
                // 自定义输出文件名 , 如果你 Entity 设置了前后缀、此处注意 xml 的名称会跟着发生变化!!
                return projectPath + "/src/main/resources/mapper/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
            }
        });
        /*
        cfg.setFileCreate(new IFileCreate() {
            @Override
            public boolean isCreate(ConfigBuilder configBuilder, FileType fileType, String filePath) {
                // 判断自定义文件夹是否需要创建
                checkDir("调用默认方法创建的目录");
                return false;
            }
        });
        */
        cfg.setFileOutConfigList(focList);
        mpg.setCfg(cfg);

        // 配置模板
        TemplateConfig templateConfig = new TemplateConfig();

        // 配置自定义输出模板
        //指定自定义模板路径,注意不要带上.ftl/.vm, 会根据使用的模板引擎自动识别
        // templateConfig.setEntity("templates/entity2.java");
        // templateConfig.setService();
        // templateConfig.setController();

        //templateConfig.setXml(null);
        mpg.setTemplate(templateConfig);

        // 策略配置
        StrategyConfig strategy = new StrategyConfig();
        strategy.setNaming(NamingStrategy.underline_to_camel);
        strategy.setColumnNaming(NamingStrategy.underline_to_camel);
        //strategy.setSuperEntityClass("com.baomidou.ant.common.BaseEntity");
        strategy.setEntityLombokModel(true);
        strategy.setRestControllerStyle(true);
        //strategy.setSuperControllerClass("com.baomidou.ant.common.BaseController");
//        strategy.setInclude(scanner("表名,多个英文逗号分割").split(","));
//        strategy.setSuperEntityColumns("id");
        strategy.setControllerMappingHyphenStyle(true);
        strategy.setTablePrefix(pc.getModuleName() + "_");
        mpg.setStrategy(strategy);
        mpg.setTemplateEngine(new VelocityTemplateEngine());
        mpg.execute();
    }
 
Example #26
Source Project: charging_pile_cloud   Author: konglingyinxia   File: AdminMpGenerator.java    License: 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("D:\\code");
        gc.setAuthor("kongling");
        gc.setOpen(true);
        gc.setSwagger2(false);
        gc.setDateType(DateType.ONLY_DATE);
        gc.setBaseResultMap(true);
        gc.setBaseColumnList(true);
        gc.setSwagger2(true);
        gc.setActiveRecord(true);
        mpg.setGlobalConfig(gc);

        // 数据源配置
        DataSourceConfig dsc = new DataSourceConfig();
        dsc.setUrl("jdbc:mysql://127.0.0.1:3306/charging_pile?serverTimezone=UTC");
        // dsc.setSchemaName("public");
        dsc.setDriverName("com.mysql.jdbc.Driver");
        dsc.setUsername("root");
        dsc.setPassword("root");
        mpg.setDataSource(dsc);

        // 包配置
        PackageConfig pc = new PackageConfig();
        //pc.setModuleName(scanner("模块名"));
        pc.setParent(scanner("包名,例如:com.sskj.admin"));
        mpg.setPackageInfo(pc);
        // 自定义配置
        InjectionConfig cfg = new InjectionConfig() {
            @Override
            public void initMap() {
                // to do nothing
            }
        };

        // 如果模板引擎是 freemarker
        String templatePath = "/templates/mapper.xml";
        // 如果模板引擎是 velocity
        // String templatePath = "/templates/mapper.xml.vm";

        // 自定义输出配置
        List<FileOutConfig> focList = new ArrayList<>();
        // 自定义配置会被优先输出
/*
		focList.add(new FileOutConfig(templatePath) {
			@Override
			public String outputFile(TableInfo tableInfo) {
				// 自定义输出文件名 , 如果你 Entity 设置了前后缀、此处注意 xml 的名称会跟着发生变化!!
				return projectPath + "/src/main/resources/mapper/" + pc.getModuleName()
						+ "/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
			}
		});
*/

        cfg.setFileOutConfigList(focList);
        mpg.setCfg(cfg);

        // 配置模板
        TemplateConfig templateConfig = new TemplateConfig();

        // 配置自定义输出模板
        //指定自定义模板路径,注意不要带上.ftl/.vm, 会根据使用的模板引擎自动识别
        // templateConfig.setEntity("templates/entity2.java");
        // templateConfig.setService();
        // templateConfig.setController();

        templateConfig.setXml(templatePath);
        mpg.setTemplate(templateConfig);

        // 策略配置
        StrategyConfig strategy = new StrategyConfig();
        strategy.setNaming(NamingStrategy.underline_to_camel);
        //	strategy.setSuperEntityClass("com.baomidou.ant.common.BaseEntity");
        //RestController
        strategy.setRestControllerStyle(false);
        //strategy.setSuperControllerClass("com.baomidou.ant.common.BaseController");
        strategy.setInclude(scanner("表名"));
      //  strategy.setSuperEntityColumns("id");
        strategy.setControllerMappingHyphenStyle(false);
        strategy.setTablePrefix(pc.getModuleName() + "_");
        strategy.setEntityTableFieldAnnotationEnable(true);
        strategy.setEntityLombokModel(true);
        /**
         * boolean 是否一处前缀is
         */
        strategy. setEntityBooleanColumnRemoveIsPrefix(false);
        mpg.setStrategy(strategy);
        mpg.setTemplateEngine(new FreemarkerTemplateEngine());
        mpg.execute();
    }
 
Example #27
Source Project: springboot-restful-starter   Author: ocubexo   File: CodeGenerator.java    License: 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 #28
Source Project: cola-cloud   Author: leecho   File: GenerateService.java    License: MIT License 4 votes vote down vote up
@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 #29
Source Project: pig   Author: magicgis   File: PigResourcesGenerator.java    License: MIT License 4 votes vote down vote up
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();
}
 
Example #30
Source Project: spring-cloud-shop   Author: SiGuiyang   File: GeneratorService.java    License: 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();
}