/** * @author admin * @Description * 转大写 */ public class HashMapUpper<V> extends HashMap<String, V> { /** * 复写put方法,因为Mybatis底层给Map赋值就是调用的put方法 * * @param key * @param value * @return */ @Override public V put(String key, V value) { return super.put(key.toUpperCase(), value); } /** * 复写get方法 * * @param key * @return */ @Override public V get(Object key) { if (key instanceof String) { return super.get(((String) key).toUpperCase()); } else { return super.get(key); } } }
/** * @author admin * @Description 将下划线转为驼峰格式 */ public class HashMapToCamel<V> extends HashMap<String, V> { public static final char UNDERLINE = '_'; /** * 复写put方法,因为Mybatis底层给Map赋值就是调用的put方法 * * @param key * @param value * @return */ @Override public V put(String key, V value) { return super.put(underlineToCamel(key), value); } /** * 复写get方法 * * @param key * @return */ @Override public V get(Object key) { if (key instanceof String) { return super.get(underlineToCamel(key + "")); } else { return super.get(key); } } /** * 将下划线转为驼峰格式 * * @param param * @return */ public static String underlineToCamel(String param) { if (param == null || "".equals(param.trim())) { return ""; } int len = param.length(); StringBuilder sb = new StringBuilder(len); for (int i = 0; i < len; i++) { char c = param.charAt(i); if (c == UNDERLINE) { if (++i < len) { sb.append(Character.toUpperCase(param.charAt(i))); } } else { sb.append(Character.toLowerCase(param.charAt(i))); } } return sb.toString(); } }
你好世界!