Java字符串将数据库字段改成驼峰字段

// CODE_ID -> codeId
public static String toCamelCase(String str) {
    if (str == null) {
        return null;
    }
    str = str.toLowerCase();
    StringBuilder sb = new StringBuilder();
    boolean upperCase = false;
    for (int i = 0; i < str.length(); i++) {
        char c = str.charAt(i);
        if (c == '_') {
            upperCase = true;
        } else if (upperCase) {
            sb.append(Character.toUpperCase(c));
            upperCase = false;
        } else {
            sb.append(c);
        }
    }
    return sb.toString();
}

你可能感兴趣的:(笔记,数据库,java,前端)