| | |
| | | /** |
| | | * 下划线转驼峰 |
| | | */ |
| | | public static void lineToHump(JSONObject json) { |
| | | public static JSONObject lineToHump(JSONObject json) { |
| | | Pattern linePattern = Pattern.compile("_(\\w)"); |
| | | for(String str : json.keySet()) { |
| | | JSONObject newJson = new JSONObject(); |
| | | String value = ""; |
| | | for (String str : json.keySet()) { |
| | | str = str.toLowerCase(); |
| | | Matcher matcher = linePattern.matcher(str); |
| | | StringBuffer sb = new StringBuffer(); |
| | |
| | | matcher.appendReplacement(sb, matcher.group(1).toUpperCase()); |
| | | } |
| | | matcher.appendTail(sb); |
| | | json.put(sb.toString(),json.getString(str)); |
| | | value = json.getString(str); |
| | | if (StringUtil.isEmpty(value)) { |
| | | newJson.put(sb.toString(), json.getString(str)); |
| | | newJson.put(str, json.getString(str)); |
| | | continue; |
| | | } |
| | | if (value.startsWith("'")) { |
| | | value = value.replace("'", ""); |
| | | } |
| | | |
| | | if (value.endsWith("'")) { |
| | | value = value.substring(0, value.length() - 1); |
| | | } |
| | | |
| | | newJson.put(sb.toString(), value); |
| | | newJson.put(str, value); |
| | | |
| | | } |
| | | |
| | | return newJson; |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | String value = "'123'"; |
| | | if (value.startsWith("'")) { |
| | | value = value.replace("'", ""); |
| | | } |
| | | |
| | | if (value.endsWith("'")) { |
| | | value = value.substring(0, value.length() - 1); |
| | | } |
| | | System.out.printf(value); |
| | | } |
| | | |
| | | /** |
| | |
| | | return sb.toString(); |
| | | } |
| | | |
| | | /** |
| | | * 对人名进行脱敏处理,只显示姓和名字的最后一个字 |
| | | * |
| | | * @param name 原始人名 |
| | | * @return 脱敏后人名的字符串 |
| | | */ |
| | | public static String maskName(String name) { |
| | | if (name == null || name.isEmpty()) { |
| | | return name; |
| | | } |
| | | String[] parts = name.split(""); |
| | | |
| | | if(parts.length <= 2){ |
| | | return parts[0]+"*"; |
| | | } |
| | | |
| | | return parts[0]+"*" + parts[parts.length-1]; |
| | | } |
| | | |
| | | } |