| | |
| | | continue; |
| | | } |
| | | |
| | | String field = convertFiled(str.substring(0, start).trim()); |
| | | String field = camelToUnderline(str.substring(0, start).trim()); |
| | | String express = str.substring(start + 1, end).trim().toLowerCase(); |
| | | String value = str.substring(end + 1).trim(); |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * 字段转换 |
| | | * 驼峰转换为下划线 |
| | | */ |
| | | private String convertFiled(String field) { |
| | | public static String camelToUnderline(String str) { |
| | | StringBuilder sb = new StringBuilder(); |
| | | for (int i = 0, c = field.length(); i < c; i++) { |
| | | char ch = field.charAt(i); |
| | | for (int i = 0, c = str.length(); i < c; i++) { |
| | | char ch = str.charAt(i); |
| | | if (Character.isUpperCase(ch)) { |
| | | sb.append('_'); |
| | | sb.append(Character.toLowerCase(ch)); |
| | | sb.append('_').append(Character.toLowerCase(ch)); |
| | | } else { |
| | | sb.append(ch); |
| | | } |
| | | } |
| | | |
| | | return sb.toString().replaceAll("_+", "_"); |
| | | } |
| | | |
| | | /** |
| | | * 下划线转换为驼峰 |
| | | */ |
| | | public static String underlineToCamel(String str) { |
| | | StringBuilder sb = new StringBuilder(); |
| | | |
| | | boolean nextIsCapitalized = false; |
| | | for (int i = 0, c = str.length(); i < c; i++) { |
| | | char ch = str.charAt(i); |
| | | if (ch == '_') { |
| | | nextIsCapitalized = true; |
| | | continue; |
| | | } |
| | | if (nextIsCapitalized) { |
| | | sb.append(Character.toUpperCase(ch)); |
| | | nextIsCapitalized = false; |
| | | } else { |
| | | sb.append(Character.toLowerCase(c)); |
| | | } |
| | | } |
| | | |
| | | return sb.toString(); |
| | | } |
| | | |