package com.hongniu.common.quartz.factory;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @program: hongniu_serverManage
* @description: 带驼峰属性转为SQL带下划线并大写
* @author: qlinchao
* @create: 2019-02-18 14:57
**/
public class Test {
static Pattern p = Pattern.compile("[A-Z]");
public static void main(String[] args) {
String[] strArr = {"SubAccount","SubAccName","Order", "TransCode","OtherSubAccount","OtherSubAccName",
"CreMoney","PayPayeeSign","SubAccountMoney", "MerchantSqlId","SysSqlId","TradeTimes",
"PayOrderid","CurrCode","FeeAmt", "PayBankNo","TranDate","FreezeAccbal",
"BusiSummary","CustPayFee","MerchantFee","AppType", "FeeFlag","Remark1","Remark2", "TransCodeId","Remark3","Remark4","Remark5"
};
for (int i = 0; i <strArr.length ; i++) {
String s = upperCharToUnderLine(strArr[i]).toUpperCase();
System.out.println(s);
}
}
public static String upperCharToUnderLine(String param) {
if (param == null || param.equals("")) {
return "";
}
StringBuilder builder = new StringBuilder(param);
Matcher mc = p.matcher(param);
int i = 0;
while (mc.find()) {
// System.out.println(builder.toString());
// System.out.println("mc.start():" + mc.start() + ", i: " + i);
// System.out.println("mc.end():" + mc.start() + ", i: " + i);
builder.replace(mc.start() + i, mc.end() + i, "_" + mc.group().toLowerCase());
i++;
}
if ('_' == builder.charAt(0)) {
builder.deleteCharAt(0);
}
return builder.toString();
}
}
参考:https://blog.csdn.net/m0_37749778/article/details/82148874