All Downloads are FREE. Search and download functionalities are using the official Maven repository.

pub.codex.common.utils.TranslateUtil Maven / Gradle / Ivy

package pub.codex.common.utils;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.text.WordUtils;
import pub.codex.common.column.BaseColumn;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TranslateUtil {
    /**
     * List转换成Map
     *
     * @param interfaceColumn
     * @return
     */
    public static Map transformUtils(List interfaceColumn) {
        if (interfaceColumn == null) {
            return null;
        }
        Map map = new HashMap<>();
        for (BaseColumn baseColumn : interfaceColumn) {
            map.put(baseColumn.getAttrname(), baseColumn);
        }
        return map;
    }

    /**
     * 表名转换成Java类名
     */
    public static String tableToJava(String tableName, String tablePrefix) {
        if (StringUtils.isNotBlank(tablePrefix)) {
            tableName = tableName.replace(tablePrefix, "" );
        }
        return columnToJava(tableName);
    }

    /**
     * 列名转换成Java属性名
     */
    public static String columnToJava(String columnName) {
        return WordUtils.capitalizeFully(columnName, new char[]{'_'}).replace("_", "" );
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy