mybatis-plusコード生成構成テスト

3129 ワード

public static void main(String[] args) {
        // 1、 
        AutoGenerator autoGenerator = new AutoGenerator();

        // 2、 
        // 2-1、 
        GlobalConfig globalConfig = new GlobalConfig();
        String projectPath = System.getProperty("user.dir");
        globalConfig.setOutputDir(projectPath+"/src/main/java");
        globalConfig.setAuthor("P");
        globalConfig.setOpen(false);
        globalConfig.setFileOverride(false);//  
        globalConfig.setServiceName("%sService");//  service i 
        globalConfig.setIdType(IdType.ASSIGN_ID); //  id
        globalConfig.setDateType(DateType.ONLY_DATE);
        globalConfig.setEnableCache(false); // mybaits 
        globalConfig.setBaseResultMap(true);

//        globalConfig.setSwagger2(true);
        autoGenerator.setGlobalConfig(globalConfig);

        // 2-2、 
        DataSourceConfig dataSourceConfig = new DataSourceConfig();
        dataSourceConfig.setUrl("jdbc:mysql://127.0.0.1:3306/cx-master?autoReconnect=true&useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&zeroDateTimeBehavior=convertToNull&useSSL=false");
        dataSourceConfig.setDriverName("com.mysql.jdbc.Driver");
        dataSourceConfig.setUsername("root");
        dataSourceConfig.setPassword("root");
        autoGenerator.setDataSource(dataSourceConfig);

        // 2-3、 
        PackageConfig packageConfig = new PackageConfig();
        packageConfig.setModuleName("project");
        packageConfig.setParent("com.cx");
        packageConfig.setEntity("entity");
        packageConfig.setMapper("mapper");
        packageConfig.setXml("mapper.mapping");
        packageConfig.setService("service");
        packageConfig.setController("controller");
        autoGenerator.setPackageInfo(packageConfig);

        // 2-4、 
        StrategyConfig strategyConfig = new StrategyConfig();
        strategyConfig.setInclude("sys_user");//  
        strategyConfig.setNaming(NamingStrategy.underline_to_camel);
        strategyConfig.setEntityLombokModel(true);//  lombok
        strategyConfig.setChainModel(true);//  
        strategyConfig.setLogicDeleteFieldName("deleted");
        strategyConfig.setTablePrefix("sys_");// 

        //2-4-1、 
        TableFill createUserId = new TableFill("create_user_id" , FieldFill.INSERT);
        TableFill updateUserId = new TableFill("update_user_id", FieldFill.INSERT_UPDATE);
        ArrayList tableFills = new ArrayList<>();
        tableFills.add(createUserId);
        tableFills.add(updateUserId);
        strategyConfig.setTableFillList(tableFills);

        // 2-4-2、 
        strategyConfig.setVersionFieldName("version");

        strategyConfig.setRestControllerStyle(true);
        strategyConfig.setControllerMappingHyphenStyle(true); // localhost:8080/hello_id_2
        autoGenerator.setStrategy(strategyConfig);

        autoGenerator.execute();

    }