下划线和驼峰转换

public void assembleData(Map resultMap,
Map 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 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);
}
}
}

你可能感兴趣的:(java)