package cn.liyy.upload.utiles;import java.util.regex.Pattern;publicclassConvertName{publicstatic String convertName (String name){
String result ="";if(name != null){if(!Pattern.compile(".*[_]+.*").matcher( name ).matches()){//是否是下划线命名if(!Pattern.compile(".*[A-Z]+.*").matcher( name ).matches()){//是否包含大写字母return name;}
result = name.replaceAll("([a-z])([A-Z])","$1"+"_"+"$2").toUpperCase();}else{for(String s : name.split("_")){
result = result + s.substring(0,1).toUpperCase()+s.substring(1).toLowerCase();}
result=result.substring(0,1).toLowerCase()+result.substring(1);}}else{return null;}return result;}}
publicclassConvertName{publicstatic String convertName (String name){
String result ="";if(name != null){
StringBuffer sb =newStringBuffer();if(!Pattern.compile(".*[_]+.*").matcher( name ).matches()){//是否是下划线命名if(!Pattern.compile(".*[A-Z]+.*").matcher( name ).matches()){//是否包含大写字母return name;}char[] chars = name.toCharArray();for(int i =0; i < chars.length; i++){if(Character.isUpperCase( chars[i])){
sb.append("_"+ chars[i]);}else{
sb.append( chars[i]);}}
result = sb.toString().toUpperCase();if(result.substring(0,1).equals("_")){//是否以"_"开始
result = result.substring(1);}}else{if(name.substring( name.length()-1).equals("_")){//结尾是否是"_"
name = name.substring(0, name.length()-1);}
name = name.toLowerCase();char[] chars = name.toCharArray();for(int i =0; i < chars.length; i++){if(chars[i]=='_'){
sb.append( Character.toUpperCase( chars[i +1]));
i++;}else{
sb.append( chars[i]);}}
result = sb.toString();}}else{return null;}return result;}}