반응형
Camelcase -> Snakecase 변환
public static String convertCamelToSnake(String str){
String regex = "([a-z])([A-Z])";
String replacement = "$1_$2";
String value = "";
value = str.replaceAll(regex, replacement).toLowerCase();
return value;
}
Snakecase -> Camelcase 변환
public static String convertSnakeToCamel(String str) {
if (str.indexOf('_') < 0 && Character.isLowerCase(str.charAt(0))) {
return str;
}
StringBuilder result = new StringBuilder();
boolean nextUpper = false;
int len = str.length();
for (int i = 0; i < len; i++) {
char currentChar = str.charAt(i);
if (currentChar == '_') {
nextUpper = true;
} else {
if (nextUpper) {
result.append(Character.toUpperCase(currentChar));
nextUpper = false;
} else {
result.append(Character.toLowerCase(currentChar));
}
}
}
return result.toString();
}
반응형
'Back > Spring Java' 카테고리의 다른 글
OutputStream를 이용한 파일생성 (0) | 2020.04.01 |
---|---|
No 'Access-Control-Allow-Origin' header is present on the requested resource. (CORS policy) (0) | 2020.03.02 |
Class Object Entity convert to Map (0) | 2020.01.14 |
JPA findAll Specification (0) | 2020.01.14 |
BeanUtils.copyProperties (0) | 2019.12.23 |