SwitchItem

/**
 * 根据下划线字段转驼峰字段
 * 
 * @param item 下划线字段
 * @return 驼峰字段
 */
private String SwitchHump(String item) {
   while (true) {
      if (item.contains("_")) {
         int index = item.indexOf("_");
         String value = item.substring(index + 1, index + 2);
         value = value.toUpperCase();
         item = item.replace(item.substring(index, index + 2), value);
      } else {
         break;
      }
   }
   return item;
}

/**
 * 将驼峰转为下划线
 * 
 * @param item 驼峰字段
 * @return 下划线字段
 */
public String SwitchUnderline(String item) {
   String num = "0123456789";
   String result = "";
   for (int index = 0; index < item.length(); index++) {
      String value = item.substring(index, index + 1);
      if (num.contains(value)) {
         value = "_" + value;
      } else if (Character.isUpperCase(value.charAt(0))) {
         value = "_" + value.toLowerCase();
      }
      result += value;
   }
   return result;
}

发表回复

您的电子邮箱地址不会被公开。

8 + 1 =