+ 修改转驼峰方法增加全大写转换,支持ORACLE
This commit is contained in:
parent
7d5c2b285f
commit
bb85d4fc06
|
@ -62,7 +62,6 @@ public class DictionaryServiceImpl extends BaseServiceImpl<DictionaryMapper, Dic
|
|||
if(V.isEmpty(voList)){
|
||||
return;
|
||||
}
|
||||
getFieldName = S.toLowerCaseCamel(getFieldName);
|
||||
bindingFieldTo(voList)
|
||||
.link(FIELD_NAME_ITEM_NAME, setFieldName)
|
||||
.joinOn(getFieldName, FIELD_NAME_ITEM_VALUE)
|
||||
|
@ -100,4 +99,4 @@ public class DictionaryServiceImpl extends BaseServiceImpl<DictionaryMapper, Dic
|
|||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -111,7 +111,7 @@ public class S extends StringUtils{
|
|||
}
|
||||
|
||||
/***
|
||||
* 转换成蛇形命名(用于Java属性转换为数据库列名)
|
||||
* 转换成小写蛇形命名(用于Java属性转换为小写数据库列名)
|
||||
* @param camelCaseStr
|
||||
* @return
|
||||
*/
|
||||
|
@ -126,11 +126,8 @@ public class S extends StringUtils{
|
|||
if(sb.length() > 0){
|
||||
sb.append(Cons.SEPARATOR_UNDERSCORE);
|
||||
}
|
||||
sb.append(Character.toLowerCase(c));
|
||||
}
|
||||
else{
|
||||
sb.append(c);
|
||||
}
|
||||
sb.append(Character.toLowerCase(c));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
@ -144,27 +141,31 @@ public class S extends StringUtils{
|
|||
if(V.isEmpty(snakeCaseStr)){
|
||||
return null;
|
||||
}
|
||||
// 不包含_,直接return
|
||||
// 不包含_
|
||||
if(!snakeCaseStr.contains(Cons.SEPARATOR_UNDERSCORE)){
|
||||
return snakeCaseStr;
|
||||
}
|
||||
char[] chars = snakeCaseStr.toCharArray();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
boolean upperCase = false;
|
||||
for (char c : chars){
|
||||
if(Cons.SEPARATOR_UNDERSCORE.equals(Character.toString(c))){
|
||||
upperCase = true;
|
||||
continue;
|
||||
}
|
||||
if(upperCase){
|
||||
sb.append(Character.toUpperCase(c));
|
||||
upperCase = false;
|
||||
// 全大写直接return小写
|
||||
if(snakeCaseStr.toUpperCase().equals(snakeCaseStr)){
|
||||
return snakeCaseStr.toLowerCase();
|
||||
}
|
||||
// 其他return 首字母小写
|
||||
else{
|
||||
sb.append(c);
|
||||
return uncapFirst(snakeCaseStr);
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
// 包含_
|
||||
String result = null;
|
||||
String[] words = snakeCaseStr.split(Cons.SEPARATOR_UNDERSCORE);
|
||||
for(String word : words){
|
||||
if(V.notEmpty(word)){
|
||||
if(result == null){
|
||||
result = word.toLowerCase();
|
||||
}
|
||||
else{
|
||||
result += word.substring(0, 1).toUpperCase() + word.substring(1).toLowerCase();
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/***
|
||||
|
@ -285,7 +286,7 @@ public class S extends StringUtils{
|
|||
*/
|
||||
public static String uncapFirst(String input){
|
||||
if(input != null){
|
||||
return String.valueOf(input.charAt(0)).toLowerCase() + input.substring(1);
|
||||
return Character.toLowerCase(input.charAt(0)) + input.substring(1);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -296,7 +297,7 @@ public class S extends StringUtils{
|
|||
*/
|
||||
public static String capFirst(String input){
|
||||
if(input != null){
|
||||
return String.valueOf(input.charAt(0)).toUpperCase() + input.substring(1);
|
||||
return Character.toUpperCase(input.charAt(0)) + input.substring(1);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -14,9 +14,10 @@ public class STest {
|
|||
|
||||
@Test
|
||||
public void testToSnakeCase(){
|
||||
String str = "myOrgName";
|
||||
String camelCaseStr = "myOrgName";
|
||||
String snakeCaseStr = "my_org_name";
|
||||
Assert.assertEquals(S.toSnakeCase(str), snakeCaseStr);
|
||||
Assert.assertEquals(S.toSnakeCase(camelCaseStr), snakeCaseStr);
|
||||
Assert.assertEquals(S.toSnakeCase(S.capFirst(camelCaseStr)), snakeCaseStr);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -24,6 +25,7 @@ public class STest {
|
|||
String snakeCaseStr = "my_org_name";
|
||||
String camelCaseStr = "myOrgName";
|
||||
Assert.assertEquals(S.toLowerCaseCamel(snakeCaseStr), camelCaseStr);
|
||||
Assert.assertEquals(S.toLowerCaseCamel(snakeCaseStr.toUpperCase()), camelCaseStr);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -33,4 +35,4 @@ public class STest {
|
|||
Assert.assertEquals(S.uncapFirst("HelloWorld"), text);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue