我正嘗試從POJO字段生成數據庫列名。例如,如果POJO具有字段作爲如何將pojo屬性轉換爲數據庫列名
origOrderDate --> ORIG_ORDER_DATE
custName --> CUST_NAME
firstOrigDatePort --> FIRST_ORIG_DATE_PORT
...
...
我有下面的代碼,
String testStr = "origOrderDate";
String regEx = "([A-Z])";
Pattern pattern = Pattern.compile(regEx);
Matcher matcher = pattern.matcher(testStr);
StringBuffer sb = new StringBuffer();
while (matcher.find()) {
System.out.printf("Found %d, of capital letters in %s%n", matcher.groupCount(), testStr);
matcher.appendReplacement(sb, "_$1");
}
System.out.println(sb.toString().toUpperCase());
它失去結束字符串的一部分。有任何想法嗎?
ORIG_ORDER_D
你需要把['matcher.appendTail(SB)'](http://docs.oracle.com/javase/7/docs/ api/java/util/regex/Matcher.html#appendTail%28java.lang.StringBuffer%29)。 – aioobe