Oracle数据库用mybatis的pageHelper分页后,用Map接收,字段名全部大写的,固加了一层转换。
package com.glaze.ssmdemo.until;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/**
* @Description:
* @auther GlazeChou
* @Date 2020/6/3 11:50 下午:21
* @Version 1.0
*/
public class MapUntil {
/**
* 把map的key转换成驼峰命名
* @param map
* @return
*/
public static Map<String, Object> toReplaceKeyLow(Map<String, Object> map) {
Map re_map = new HashMap();
if (re_map != null) {
Iterator var2 = map.entrySet().iterator();
while (var2.hasNext()) {
Map.Entry<String, Object> entry = (Map.Entry) var2.next();
re_map.put(underlineToCamel((String) entry.getKey()), map.get(entry.getKey()));
}
map.clear();
}
return re_map;
}
/**
* 把list中的map的key转为小驼峰
* @param list
* @return
*/
public static List<Map<String, Object>> toCamelForList(List<Map<String, Object>> list) {
return list.stream().map(MapUntil::toReplaceKeyLow).collect(Collectors.toList());
}
public static final char UNDERLINE = '_';
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();
}
public static void main(String[] args) {
String str="USER_NAME";
String s = underlineToCamel(str);
System.out.println(s);
Map<String, Object> map = new HashMap<>();
map.put("USER_NAME","tom");
map.put("USER_PASSWORD","tom");
map.put("STATUS","tom");
map.put("DEPT_NO","tom");
map.put("DEPT_NAME","tom");
map.put("USER_EMAIL","tom");
Map<String, Object> remap = toReplaceKeyLow(map);
System.out.println(remap);
}
}
转换后的输出