格式单表查询语句字段驼峰式(java版)

编程

public class TransSelectSql {

public static void main(String[] args) {

String baseSql = "SELECT

" +

"a.session_id,

" +

"a.login_name,

" +

"a.ip,

" +

"a.login_location,

" +

"a.browser,

" +

"a.os,

" +

"a.status,

" +

"a.create_time,

" +

"a.last_access_time,

" +

"a.expire_time

" +

"FROM

" +

"sys_user_online a";

System.out.println(baseSql.indexOf("SELECT"));

System.out.println(baseSql.indexOf("FROM"));

int selectIndex = baseSql.indexOf("SELECT");

int fromIndex = baseSql.indexOf("FROM");

System.out.println("==>selectIndex:"+ selectIndex +", fromIndex:" + fromIndex);

String forReplaceStr = baseSql.substring(selectIndex + 6, fromIndex).replaceAll("[\t\n\r]", "");;

String[] forReplaceStrs = forReplaceStr.split(",");

String allSql = "SELECT ";

for(int i = 0; i < forReplaceStrs.length; i++) {

String formatStr = forReplaceStrs[i];

if(forReplaceStrs[i].indexOf("_") > 0) {

formatStr = formatColumn(forReplaceStrs[i]);

}

allSql += formatStr + ", ";

}

System.out.println("===>: " + allSql.substring(0, allSql.length() - 2) + " " + baseSql.substring(fromIndex, baseSql.length()));

}

public static String formatColumn(String repal) {

String[] repals = repal.split("_");

int i = 0;

String[] repalsS = new String[repals.length];

for (String repalStr : repals) {

i++;

if(i < 2) {

repalsS[i-1] = repals[i-1];

continue;

}

String tempStr = repalStr.substring(0, 1).toUpperCase() + repalStr.substring(1, repalStr.length());

repalsS[i-1] = tempStr;

}

String resultStr = "";

for(String tempRepla : repalsS) {

resultStr += tempRepla;

}

String resultColumn = repal + " " + resultStr.split("\.")[1];

return resultColumn;

}

}

以上是 格式单表查询语句字段驼峰式(java版) 的全部内容, 来源链接: utcz.com/z/514275.html

回到顶部