下划线和驼峰转换

来源:互联网 发布:旺旺号是不是淘宝昵称 编辑:程序博客网 时间:2024/04/30 12:00
public void assembleData(Map<String, Object> resultMap,
Map<String, Object> configMap, String[] runDataList,
String displayName) {
for (int i = 0; i < runDataList.length; i++) {
String[] temp = runDataList[i].split("=");
String key = temp[0].trim();

String value = temp[1].trim();

//下划线和驼峰转换

while(key.contains("_")) {
Pattern p = Pattern.compile("_\\w");
Matcher m = p.matcher(key);
if (m.find()) {
String repStr = m.group();
key = key.replace(repStr, repStr.substring(1, 2).toUpperCase() + repStr.substring(2));
}
}
if(!configMap.containsKey(key)){
continue;
}else{
ObjectMapper mapper = new ObjectMapper();  
DevDatailConfig devDatailConfig = (DevDatailConfig) configMap.get(key);
displayName = devDatailConfig.getFieldName();
String json = (String) devDatailConfig.getFuncContent();

try {

//获取含有json字段

Map<String,Object> productMap = mapper.readValue(json,Map.class);
//如果是范围的话先不转换
value = (String) productMap.get(value)==null ? value : (String)productMap.get(value);
} catch (JsonParseException e) {
e.printStackTrace();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();


}
if (null != displayName) {
resultMap.put(displayName, value);
}
}
}
0 0
原创粉丝点击