Java Code Examples for com.ruoyi.generator.util.GenUtils#tableToJava()

The following examples show how to use com.ruoyi.generator.util.GenUtils#tableToJava() . 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: GenServiceImpl.java    From ruoyiplus with MIT License 6 votes vote down vote up
@Override
public TableInfo getTableInfo(String tableName, String prefix, Map<String, String[]> params) {
    TableInfo table = genMapper.selectTableByName(tableName);
    if (table != null) {
        // 查询列信息
        List<ColumnInfo> columns = genMapper.selectTableColumnsByName(tableName);
        String tn = table.getTableName();
        if (StrUtil.isNotEmpty(prefix) && tn.startsWith(prefix)) {
            tn = tn.substring(prefix.length() - 1);
        }
        // 表名转换成Java属性名
        String className = GenUtils.tableToJava(tn);
        table.setClassName(className);
        table.setClassname(StringUtils.uncapitalize(className));
        // 列信息
        table.setColumns(GenUtils.transColums(columns, params));
        // 设置主键
        table.setPrimaryKey(table.getColumnsLast());
    }
    return table;
}
 
Example 2
Source File: GenServiceImpl.java    From RuoYi with Apache License 2.0 5 votes vote down vote up
/**
 * 根据表信息生成代码
 * @param zip 生成后的压缩包
 * @param tableName 表名
 */
private void generatorCode(ZipOutputStream zip, String tableName) {
    // 查询表信息
    TableInfo table = genMapper.selectTableByName(tableName);
    // 查询列信息
    List<ColumnInfo> columns = genMapper.selectTableColumnsByName(tableName);
    // 表名转换成Java属性名
    String className = GenUtils.tableToJava(table.getTableName());
    table.setClassName(className);
    table.setClassname(StrUtil.lowerFirst(className));
    // 列信息
    table.setColumns(GenUtils.transColums(columns));
    // 设置主键
    table.setPrimaryKey(table.getColumnsLast());

    VelocityInitializer.initVelocity();

    String packageName = Global.getPackageName();
    String moduleName = GenUtils.getModuleName(packageName);

    VelocityContext context = GenUtils.getVelocityContext(table);

    // 获取模板列表
    List<String> templates = GenUtils.getTemplates();
    for (String template : templates) {
        // 渲染模板
        StringWriter sw = new StringWriter();
        Template tpl = Velocity.getTemplate(template, CharsetKit.UTF8);
        tpl.merge(context, sw);
        try {
            // 添加到zip
            zip.putNextEntry(new ZipEntry(Objects.requireNonNull(GenUtils.getFileName(template, table, moduleName))));
            IOUtils.write(sw.toString(), zip, CharsetKit.UTF8);
            IOUtils.closeQuietly(sw);
            zip.closeEntry();
        } catch (IOException e) {
            log.error("渲染模板失败,表名:" + table.getTableName(), e);
        }
    }
}