Search in sources :

Example 1 with MySqlKeyWordsHandler

use of com.baomidou.mybatisplus.generator.keywords.MySqlKeyWordsHandler in project xuxiaowei-cloud by xuxiaowei-cloud.

the class MyBatisPlusGeneratorTests method main.

public static void main(String[] args) {
    DataSourceConfig.Builder dataSourceConfig = new DataSourceConfig.Builder("jdbc:mysql://127.0.0.1:3306/xuxiaowei_cloud", "root", "root").dbQuery(new MySqlQuery()).schema("users").typeConvert(new MySqlTypeConvert()).keyWordsHandler(new MySqlKeyWordsHandler());
    String userDir = System.getProperty("user.dir");
    String fileSeparator = System.getProperty("file.separator");
    List<Module> moduleList = Arrays.asList(new Module("authorization-server", "cloud.xuxiaowei.authorizationserver"), new Module("cloud-commons-parent" + fileSeparator + "cloud-starter-core", "cloud.xuxiaowei.core"), new Module("resource-server", "cloud.xuxiaowei.resourceserver"));
    System.out.println("项目文件夹:" + userDir);
    System.out.println("模块列表:");
    for (int i = 0; i < moduleList.size(); i++) {
        Module module = moduleList.get(i);
        System.out.println("序号:" + i + ":" + module.getModuleFolder() + ":" + module.getPackageName());
    }
    int moduleNumber = scannerInt("请输入模块名序号?");
    Module module = moduleList.get(moduleNumber);
    String moduleFolder = module.getModuleFolder();
    String packageName = module.getPackageName();
    String[] packageNameSplit = packageName.split("\\.");
    String xmlFolder = packageNameSplit[packageNameSplit.length - 1];
    String mainFolder = userDir + fileSeparator + moduleFolder + fileSeparator + "src" + fileSeparator + "main";
    String javaDir = mainFolder + fileSeparator + "java";
    String xmlDir = mainFolder + fileSeparator + "resources" + fileSeparator + "mapper" + fileSeparator + xmlFolder;
    System.out.println("java 输出目录:" + javaDir);
    System.out.println("xml 输出目录:" + xmlDir);
    FastAutoGenerator.create(dataSourceConfig).globalConfig((scanner, builder) -> {
        builder.author(scanner.apply("请输入作者名称?"));
        // 禁止打开输出目录
        builder.disableOpenDir();
        // 输出目录
        builder.outputDir(javaDir);
    }).packageConfig((scanner, builder) -> {
        builder.parent(packageName);
        builder.pathInfo(Collections.singletonMap(OutputFile.xml, xmlDir));
    }).strategyConfig((scanner, builder) -> builder.addInclude(getTables(scanner.apply("请输入表名,多个英文逗号分隔?所有输入 all"))).controllerBuilder().enableRestStyle().enableHyphenStyle().mapperBuilder().enableBaseResultMap().entityBuilder().enableLombok().addTableFills(new Column("create_date", FieldFill.INSERT), new Column("update_date", FieldFill.UPDATE), new Column("create_username", FieldFill.INSERT), new Column("update_username", FieldFill.UPDATE)).logicDeleteColumnName("deleted").build()).execute();
}
Also used : Arrays(java.util.Arrays) Column(com.baomidou.mybatisplus.generator.fill.Column) MySqlTypeConvert(com.baomidou.mybatisplus.generator.config.converts.MySqlTypeConvert) Scanner(java.util.Scanner) DataSourceConfig(com.baomidou.mybatisplus.generator.config.DataSourceConfig) MybatisPlusException(com.baomidou.mybatisplus.core.exceptions.MybatisPlusException) OutputFile(com.baomidou.mybatisplus.generator.config.OutputFile) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) FastAutoGenerator(com.baomidou.mybatisplus.generator.FastAutoGenerator) MySqlQuery(com.baomidou.mybatisplus.generator.config.querys.MySqlQuery) Data(lombok.Data) FieldFill(com.baomidou.mybatisplus.annotation.FieldFill) MySqlKeyWordsHandler(com.baomidou.mybatisplus.generator.keywords.MySqlKeyWordsHandler) AllArgsConstructor(lombok.AllArgsConstructor) Collections(java.util.Collections) DataSourceConfig(com.baomidou.mybatisplus.generator.config.DataSourceConfig) MySqlTypeConvert(com.baomidou.mybatisplus.generator.config.converts.MySqlTypeConvert) MySqlQuery(com.baomidou.mybatisplus.generator.config.querys.MySqlQuery) Column(com.baomidou.mybatisplus.generator.fill.Column) MySqlKeyWordsHandler(com.baomidou.mybatisplus.generator.keywords.MySqlKeyWordsHandler)

Aggregations

FieldFill (com.baomidou.mybatisplus.annotation.FieldFill)1 MybatisPlusException (com.baomidou.mybatisplus.core.exceptions.MybatisPlusException)1 FastAutoGenerator (com.baomidou.mybatisplus.generator.FastAutoGenerator)1 DataSourceConfig (com.baomidou.mybatisplus.generator.config.DataSourceConfig)1 OutputFile (com.baomidou.mybatisplus.generator.config.OutputFile)1 MySqlTypeConvert (com.baomidou.mybatisplus.generator.config.converts.MySqlTypeConvert)1 MySqlQuery (com.baomidou.mybatisplus.generator.config.querys.MySqlQuery)1 Column (com.baomidou.mybatisplus.generator.fill.Column)1 MySqlKeyWordsHandler (com.baomidou.mybatisplus.generator.keywords.MySqlKeyWordsHandler)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Scanner (java.util.Scanner)1 AllArgsConstructor (lombok.AllArgsConstructor)1 Data (lombok.Data)1 Slf4j (lombok.extern.slf4j.Slf4j)1