• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java NamingStrategy类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.baomidou.mybatisplus.generator.config.rules.NamingStrategy的典型用法代码示例。如果您正苦于以下问题:Java NamingStrategy类的具体用法?Java NamingStrategy怎么用?Java NamingStrategy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



NamingStrategy类属于com.baomidou.mybatisplus.generator.config.rules包,在下文中一共展示了NamingStrategy类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: processName

import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy; //导入依赖的package包/类
/**
 * <p>
 * 处理表/字段名称
 * </p>
 *
 * @param name
 * @param strategy
 * @param prefix
 * @return 根据策略返回处理后的名称
 */
private String processName(String name, NamingStrategy strategy, String[] prefix) {
    boolean removePrefix = false;
    if (prefix != null && prefix.length >= 1) {
        removePrefix = true;
    }
    String propertyName;
    if (removePrefix) {
        if (strategy == NamingStrategy.underline_to_camel) {
            // 删除前缀、下划线转驼峰
            propertyName = NamingStrategy.removePrefixAndCamel(name, prefix);
        } else {
            // 删除前缀
            propertyName = NamingStrategy.removePrefix(name, prefix);
        }
    } else if (strategy == NamingStrategy.underline_to_camel) {
        // 下划线转驼峰
        propertyName = NamingStrategy.underlineToCamel(name);
    } else {
        // 不处理
        propertyName = name;
    }
    return propertyName;
}
 
开发者ID:baomidou,项目名称:mybatis-plus,代码行数:34,代码来源:ConfigBuilder.java


示例2: setStrategyConfig

import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy; //导入依赖的package包/类
/**
 * 生成策略配置
 **/
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;
}
 
开发者ID:MIYAOW,项目名称:MI-S,代码行数:33,代码来源:MybatisPlusGenerator.java


示例3: getColumnNaming

import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy; //导入依赖的package包/类
public NamingStrategy getColumnNaming() {
    if (null == columnNaming) {
        // 未指定以 naming 策略为准
        return naming;
    }
    return columnNaming;
}
 
开发者ID:baomidou,项目名称:mybatis-plus,代码行数:8,代码来源:StrategyConfig.java


示例4: processTable

import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy; //导入依赖的package包/类
/**
 * <p>
 * 处理表对应的类名称
 * </P>
 *
 * @param tableList 表名称
 * @param strategy  命名策略
 * @param config    策略配置项
 * @return 补充完整信息后的表
 */
private List<TableInfo> processTable(List<TableInfo> tableList, NamingStrategy strategy, StrategyConfig config) {
    String[] tablePrefix = config.getTablePrefix();
    String[] fieldPrefix = config.getFieldPrefix();
    for (TableInfo tableInfo : tableList) {
        tableInfo.setEntityName(strategyConfig, NamingStrategy.capitalFirst(processName(tableInfo.getName(), strategy, tablePrefix)));
        if (StringUtils.isNotEmpty(globalConfig.getMapperName())) {
            tableInfo.setMapperName(String.format(globalConfig.getMapperName(), tableInfo.getEntityName()));
        } else {
            tableInfo.setMapperName(tableInfo.getEntityName() + ConstVal.MAPPER);
        }
        if (StringUtils.isNotEmpty(globalConfig.getXmlName())) {
            tableInfo.setXmlName(String.format(globalConfig.getXmlName(), tableInfo.getEntityName()));
        } else {
            tableInfo.setXmlName(tableInfo.getEntityName() + ConstVal.MAPPER);
        }
        if (StringUtils.isNotEmpty(globalConfig.getServiceName())) {
            tableInfo.setServiceName(String.format(globalConfig.getServiceName(), tableInfo.getEntityName()));
        } else {
            tableInfo.setServiceName("I" + tableInfo.getEntityName() + ConstVal.SERIVCE);
        }
        if (StringUtils.isNotEmpty(globalConfig.getServiceImplName())) {
            tableInfo.setServiceImplName(String.format(globalConfig.getServiceImplName(), tableInfo.getEntityName()));
        } else {
            tableInfo.setServiceImplName(tableInfo.getEntityName() + ConstVal.SERVICEIMPL);
        }
        if (StringUtils.isNotEmpty(globalConfig.getControllerName())) {
            tableInfo.setControllerName(String.format(globalConfig.getControllerName(), tableInfo.getEntityName()));
        } else {
            tableInfo.setControllerName(tableInfo.getEntityName() + ConstVal.CONTROLLER);
        }
        //强制开启字段注解
        checkTableIdTableFieldAnnotation(config, tableInfo, fieldPrefix);
    }
    return tableList;
}
 
开发者ID:baomidou,项目名称:mybatis-plus,代码行数:46,代码来源:ConfigBuilder.java


示例5: getNaming

import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy; //导入依赖的package包/类
public NamingStrategy getNaming() {
    return naming;
}
 
开发者ID:baomidou,项目名称:mybatis-plus,代码行数:4,代码来源:StrategyConfig.java


示例6: setNaming

import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy; //导入依赖的package包/类
public StrategyConfig setNaming(NamingStrategy naming) {
    this.naming = naming;
    return this;
}
 
开发者ID:baomidou,项目名称:mybatis-plus,代码行数:5,代码来源:StrategyConfig.java


示例7: setColumnNaming

import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy; //导入依赖的package包/类
public StrategyConfig setColumnNaming(NamingStrategy columnNaming) {
    this.columnNaming = columnNaming;
    return this;
}
 
开发者ID:baomidou,项目名称:mybatis-plus,代码行数:5,代码来源:StrategyConfig.java


示例8: convertTableFields

import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy; //导入依赖的package包/类
/**
 * <p>
 * 将字段信息与表信息关联
 * </p>
 *
 * @param tableInfo 表信息
 * @param strategy  命名策略
 * @return
 */
private TableInfo convertTableFields(TableInfo tableInfo, NamingStrategy strategy) {
    boolean haveId = false;
    List<TableField> fieldList = new ArrayList<>();
    List<TableField> commonFieldList = new ArrayList<>();
    try {
        String tableFieldsSql = querySQL.getTableFieldsSql();
        if (QuerySQL.POSTGRE_SQL == querySQL) {
            tableFieldsSql = String.format(tableFieldsSql, dataSourceConfig.getSchemaname(), tableInfo.getName());
        } else {
            tableFieldsSql = String.format(tableFieldsSql, tableInfo.getName());
        }
        PreparedStatement preparedStatement = connection.prepareStatement(tableFieldsSql);
        ResultSet results = preparedStatement.executeQuery();
        while (results.next()) {
            TableField field = new TableField();
            String key = results.getString(querySQL.getFieldKey());
            // 避免多重主键设置,目前只取第一个找到ID,并放到list中的索引为0的位置
            boolean isId = StringUtils.isNotEmpty(key) && key.toUpperCase().equals("PRI");
            // 处理ID
            if (isId && !haveId) {
                field.setKeyFlag(true);
                if (isKeyIdentity(results)) {
                    field.setKeyIdentityFlag(true);
                }
                haveId = true;
            } else {
                field.setKeyFlag(false);
            }
            // 处理其它信息
            field.setName(results.getString(querySQL.getFieldName()));
            field.setType(results.getString(querySQL.getFieldType()));
            field.setPropertyName(strategyConfig, processName(field.getName(), strategy));
            field.setColumnType(dataSourceConfig.getTypeConvert().processTypeConvert(field.getType()));
            field.setComment(results.getString(querySQL.getFieldComment()));
            if (strategyConfig.includeSuperEntityColumns(field.getName())) {
                // 跳过公共字段
                commonFieldList.add(field);
                continue;
            }
            // 填充逻辑判断
            List<TableFill> tableFillList = this.getStrategyConfig().getTableFillList();
            if (null != tableFillList) {
                for (TableFill tableFill : tableFillList) {
                    if (tableFill.getFieldName().equals(field.getName())) {
                        field.setFill(tableFill.getFieldFill().name());
                        break;
                    }
                }
            }
            fieldList.add(field);
        }
    } catch (SQLException e) {
        System.err.println("SQL Exception:" + e.getMessage());
    }
    tableInfo.setFields(fieldList);
    tableInfo.setCommonFields(commonFieldList);
    return tableInfo;
}
 
开发者ID:baomidou,项目名称:mybatis-plus,代码行数:68,代码来源:ConfigBuilder.java


示例9: generateByTables

import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy; //导入依赖的package包/类
private void generateByTables(String packageName, String... tableNames) {
    GlobalConfig config = new GlobalConfig();
    String dbUrl = "jdbc:mysql://localhost:3306/mybatis-plus";
    DataSourceConfig dataSourceConfig = new DataSourceConfig();
    dataSourceConfig.setDbType(DbType.MYSQL)
        .setUrl(dbUrl)
        .setUsername("root")
        .setPassword("")
        .setDriverName("com.mysql.jdbc.Driver");
    StrategyConfig strategyConfig = new StrategyConfig();
    strategyConfig
        .setCapitalMode(true)
        .setEntityLombokModel(false)
        .setDbColumnUnderline(true)
        .setNaming(NamingStrategy.underline_to_camel)
        .entityTableFieldAnnotationEnable(enableTableFieldAnnotation)
        .fieldPrefix(fieldPrefix)//test_id -> id, test_type -> type
        .setInclude(tableNames);//修改替换成你需要的表名,多个表名传数组
    config.setActiveRecord(false)
        .setIdType(tableIdType)
        .setAuthor("K神带你飞")
        .setOutputDir("d:\\codeGen")
        .setFileOverride(true);
    if (!serviceClassNameStartWithI) {
        config.setServiceName("%sService");
    }
    new AutoGenerator().setGlobalConfig(config)
        .setDataSource(dataSourceConfig)
        .setStrategy(strategyConfig)
        .setPackageInfo(
            new PackageConfig()
                .setParent(packageName)
                .setController("controller")
                .setEntity("entity")
        ).execute();
}
 
开发者ID:baomidou,项目名称:mybatis-plus,代码行数:37,代码来源:CodeGeneratorTest.java



注:本文中的com.baomidou.mybatisplus.generator.config.rules.NamingStrategy类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java EvernoteAuth类代码示例发布时间:2022-05-23
下一篇:
Java ScaleTransitionBuilder类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap