Search in sources :

Example 1 with IColumnType

use of com.baomidou.mybatisplus.generator.config.rules.IColumnType in project orion-ops by lijiahangmax.

the class CodeGenerator method runGenerator.

/**
 * 代码生成器
 */
private static void runGenerator() {
    // 全局配置
    GlobalConfig gbConfig = new GlobalConfig().setActiveRecord(false).setAuthor(Const.ORION_AUTHOR).setOutputDir("D:/MP/").setFileOverride(true).setIdType(IdType.AUTO).setServiceName("%sService").setServiceImplName("%sServiceImpl").setEntityName("%sDO").setMapperName("%sDAO").setXmlName("%sMapper").setControllerName("%sController").setSwagger2(false).setKotlin(false).setBaseResultMap(true).setEnableCache(false).setDateType(DateType.ONLY_DATE).setBaseColumnList(true);
    // 数据源配置
    DataSourceConfig dsConfig = new DataSourceConfig().setDbType(DbType.MYSQL).setDriverName("com.mysql.cj.jdbc.Driver").setUrl("jdbc:mysql://localhost:3306/orion-ops?characterEncoding=utf8").setUsername("root").setPassword("admin123").setTypeConvert(new MySqlTypeConvert() {

        @Override
        public IColumnType processTypeConvert(GlobalConfig globalConfig, String fieldType) {
            if (fieldType.toLowerCase().contains("tinyint")) {
                return DbColumnType.INTEGER;
            }
            return super.processTypeConvert(globalConfig, fieldType);
        }
    });
    // 策略配置
    StrategyConfig stConfig = new StrategyConfig().setCapitalMode(true).setEntityTableFieldAnnotationEnable(true).setEntityLombokModel(true).setRestControllerStyle(true).setControllerMappingHyphenStyle(false).setEntityBooleanColumnRemoveIsPrefix(false).setNaming(NamingStrategy.underline_to_camel).setEntityColumnConstant(false).setChainModel(false).setTablePrefix("").setFieldPrefix("").setInclude("web_side_message");
    // 包名策略配置
    PackageConfig pkConfig = new PackageConfig().setParent("com.orion.ops").setMapper("dao").setService("service").setServiceImpl("service.impl").setController("controller").setEntity("entity.domain").setXml("mapper");
    // 整合配置
    AutoGenerator ag = new AutoGenerator().setGlobalConfig(gbConfig).setDataSource(dsConfig).setStrategy(stConfig).setPackageInfo(pkConfig);
    // 执行
    ag.execute();
}
Also used : IColumnType(com.baomidou.mybatisplus.generator.config.rules.IColumnType) StrategyConfig(com.baomidou.mybatisplus.generator.config.StrategyConfig) DataSourceConfig(com.baomidou.mybatisplus.generator.config.DataSourceConfig) GlobalConfig(com.baomidou.mybatisplus.generator.config.GlobalConfig) MySqlTypeConvert(com.baomidou.mybatisplus.generator.config.converts.MySqlTypeConvert) PackageConfig(com.baomidou.mybatisplus.generator.config.PackageConfig) AutoGenerator(com.baomidou.mybatisplus.generator.AutoGenerator)

Aggregations

AutoGenerator (com.baomidou.mybatisplus.generator.AutoGenerator)1 DataSourceConfig (com.baomidou.mybatisplus.generator.config.DataSourceConfig)1 GlobalConfig (com.baomidou.mybatisplus.generator.config.GlobalConfig)1 PackageConfig (com.baomidou.mybatisplus.generator.config.PackageConfig)1 StrategyConfig (com.baomidou.mybatisplus.generator.config.StrategyConfig)1 MySqlTypeConvert (com.baomidou.mybatisplus.generator.config.converts.MySqlTypeConvert)1 IColumnType (com.baomidou.mybatisplus.generator.config.rules.IColumnType)1