com.baomidou.mybatisplus.generator.config.po.TableInfo Java Examples

The following examples show how to use com.baomidou.mybatisplus.generator.config.po.TableInfo. 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: AbstractGeneratorConfig.java    From MeetingFilm with Apache License 2.0 6 votes vote down vote up
public void doMpGeneration() {
    init();
    AutoGenerator autoGenerator = new AutoGenerator();
    autoGenerator.setGlobalConfig(globalConfig);
    autoGenerator.setDataSource(dataSourceConfig);
    autoGenerator.setStrategy(strategyConfig);
    autoGenerator.setPackageInfo(packageConfig);
    autoGenerator.execute();
    destory();

    //获取table信息,用于guns代码生成
    List<TableInfo> tableInfoList = autoGenerator.getConfig().getTableInfoList();
    if (tableInfoList != null && tableInfoList.size() > 0) {
        this.tableInfo = tableInfoList.get(0);
    }
}
 
Example #2
Source File: GenerateController.java    From open-cloud with MIT License 6 votes vote down vote up
/**
 * 获取所有表信息
 *
 * @return
 */
@ApiOperation(value = "获取所有表信息", notes = "获取所有表信息")
@PostMapping("/tables")
public ResultBody<List<TableInfo>> tables(
        @RequestParam(value = "type") String type,
        @RequestParam(value = "driverName") String driverName,
        @RequestParam(value = "url") String url,
        @RequestParam(value = "username") String username,
        @RequestParam(value = "password") String password
) {
    GlobalConfig gc = new GlobalConfig();
    // 数据源配置
    DataSourceConfig dsc = new DataSourceConfig();
    dsc.setDbType(DbType.getDbType(type));
    dsc.setDriverName(driverName);
    dsc.setUrl(url);
    dsc.setUsername(username);
    dsc.setPassword(password);
    StrategyConfig strategy = new StrategyConfig();
    TemplateConfig templateConfig = new TemplateConfig();
    ConfigBuilder config = new ConfigBuilder(new PackageConfig(), dsc, strategy, templateConfig, gc);
    List<TableInfo> list = config.getTableInfoList();
    return ResultBody.ok().data(list);
}
 
Example #3
Source File: MysqlGenerator.java    From xmanager with Apache License 2.0 5 votes vote down vote up
/**
 * 页面生成的文件名
 */
private static String getGeneratorViewPath(String viewOutputDir, TableInfo tableInfo, String suffixPath) {
	String name = StringUtils.firstToLowerCase(tableInfo.getEntityName());
	String path = viewOutputDir + "/" + name + "/" + name + suffixPath;
	File viewDir = new File(path).getParentFile();
	if (!viewDir.exists()) {
		viewDir.mkdirs();
	}
	return path;
}
 
Example #4
Source File: BladeCodeGenerator.java    From blade-tool with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 页面生成的文件名
 */
private String getGeneratorViewPath(String viewOutputDir, TableInfo tableInfo, String suffixPath) {
	String name = StringUtils.firstToLowerCase(tableInfo.getEntityName());
	String path = viewOutputDir + "/" + name + "/" + name + suffixPath;
	File viewDir = new File(path).getParentFile();
	if (!viewDir.exists()) {
		viewDir.mkdirs();
	}
	return path;
}
 
Example #5
Source File: GenerateController.java    From open-cloud with MIT License 5 votes vote down vote up
@ApiOperation(value = "代码生成并下载", notes = "代码生成并下载")
@PostMapping("/execute")
public ResultBody<List<TableInfo>> execute(
        @RequestParam(value = "type") String type,
        @RequestParam(value = "driverName") String driverName,
        @RequestParam(value = "url") String url,
        @RequestParam(value = "username") String username,
        @RequestParam(value = "password") String password,
        @RequestParam(value = "author") String author,
        @RequestParam(value = "parentPackage") String parentPackage,
        @RequestParam(value = "moduleName") String moduleName,
        @RequestParam(value = "includeTables") String includeTables,
        @RequestParam(value = "tablePrefix") String tablePrefix
) throws Exception {
    String outputDir = System.getProperty("user.dir") + File.separator + "temp" + File.separator + "generator" + File.separator + DateUtils.getCurrentTimestampStr();
    GenerateConfig config = new GenerateConfig();
    config.setDbType(DbType.getDbType(type));
    config.setJdbcUrl(url);
    config.setJdbcUserName(username);
    config.setJdbcPassword(password);
    config.setJdbcDriver(driverName);
    config.setAuthor(author);
    config.setParentPackage(parentPackage);
    config.setModuleName(moduleName);
    config.setIncludeTables(includeTables.split(","));
    config.setTablePrefix(tablePrefix.split(","));
    config.setOutputDir(outputDir);
    GeneratorService.execute(config);
    String fileName = moduleName + ".zip";
    String filePath = outputDir + File.separator + fileName;
    // 压缩目录
    String[] srcDir = {outputDir + File.separator + (parentPackage.substring(0, parentPackage.indexOf(".")))};
    ZipUtil.toZip(srcDir, filePath, true);
    Map data = Maps.newHashMap();
    data.put("filePath", filePath);
    data.put("fileName", fileName);
    return ResultBody.ok().data(data);
}
 
Example #6
Source File: PigResourcesGenerator.java    From pig with MIT License 5 votes vote down vote up
/**
 * 页面生成的文件名
 */
private static String getGeneratorViewPath(String viewOutputDir, TableInfo tableInfo, String suffixPath) {
    String name = StringUtils.firstToLowerCase(tableInfo.getEntityName());
    String path = viewOutputDir + "/" + name + "/index"  + suffixPath;
    File viewDir = new File(path).getParentFile();
    if (!viewDir.exists()) {
        viewDir.mkdirs();
    }
    return path;
}
 
Example #7
Source File: CodeGenUtil.java    From pre with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 集成
 *
 * @param dataSourceConfig 配置数据源
 * @param strategyConfig   策略配置
 * @param config           全局变量配置
 * @param packageConfig    包名配置
 */
private void atuoGenerator(DataSourceConfig dataSourceConfig, StrategyConfig strategyConfig, GlobalConfig config, PackageConfig packageConfig, String moduleName) {
    // 自定义配置
    InjectionConfig cfg = new InjectionConfig() {
        @Override
        public void initMap() {
        }
    };
    // 自定义输出配置
    List<FileOutConfig> focList = new ArrayList<>();
    // 模板引擎是 velocity
    String templatePath = "/templates/mapper.xml.vm";
    // 自定义配置会被优先输出
    focList.add(new FileOutConfig(templatePath) {
        @Override
        public String outputFile(TableInfo tableInfo) {
            // 自定义输出文件名 如果你 Entity 设置了前后缀、此处注意 xml 的名称会跟着发生变化
            return getResourcesOutputDir(moduleName) + "/src/main/resources/mapper/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
        }
    });
    cfg.setFileOutConfigList(focList);
    // 配置模板
    TemplateConfig templateConfig = new TemplateConfig();
    templateConfig.setXml(null);
    new AutoGenerator()
            .setGlobalConfig(config)
            .setDataSource(dataSourceConfig)
            .setStrategy(strategyConfig)
            .setPackageInfo(packageConfig)
            .setCfg(cfg)
            .setTemplate(templateConfig)
            .setTemplateEngine(new VelocityTemplateEngine())
            .execute();
}
 
Example #8
Source File: EntityNameRewriter.java    From cola-cloud with MIT License 5 votes vote down vote up
@Override
public void initMap() {
    if(StringUtils.isNotEmpty(entityName)){
        List<TableInfo> tableInfoList = this.getConfig().getTableInfoList();
        if(tableInfoList != null){
            tableInfoList.get(0).setComment(entityName);
        }
    }
}
 
Example #9
Source File: Generator.java    From Nickle-Scheduler 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.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 #10
Source File: CodeGenerator.java    From oauth-boot 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("jobob");
    gc.setOpen(false);
    mpg.setGlobalConfig(gc);

    // 数据源配置
    DataSourceConfig dsc = new DataSourceConfig();
    dsc.setUrl("jdbc:mysql://:3306/ant?useUnicode=true&useSSL=false&characterEncoding=utf8");
    // dsc.setSchemaName("public");
    dsc.setDriverName("com.mysql.jdbc.Driver");
    dsc.setUsername("root");
    dsc.setPassword("密码");
    mpg.setDataSource(dsc);

    // 包配置
    PackageConfig pc = new PackageConfig();
    pc.setModuleName(scanner("模块名"));
    pc.setParent("com.baomidou.ant");
    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("com.baomidou.ant.common.BaseEntity");
    strategy.setEntityLombokModel(true);
    strategy.setRestControllerStyle(true);
    strategy.setSuperControllerClass("com.baomidou.ant.common.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: PigResourcesGenerator.java    From pig with 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 #13
Source File: CodeGeneratorUtils.java    From spring-boot-shiro 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 + "/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 #14
Source File: CodeGenerator2.java    From kvf-admin 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");
        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 #15
Source File: AbstractTemplateEngine.java    From MeetingFilm with Apache License 2.0 4 votes vote down vote up
public void setTableInfo(TableInfo tableInfo) {
    this.tableInfo = tableInfo;
}
 
Example #16
Source File: AbstractTemplateEngine.java    From MeetingFilm with Apache License 2.0 4 votes vote down vote up
public TableInfo getTableInfo() {
    return tableInfo;
}
 
Example #17
Source File: MysqlGenerator.java    From spring-boot-demo with 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#2017@15");
    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();
}