下划线和驼峰转换
2015-10-20 10:28
260 查看
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);
}
}
}
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);
}
}
}
相关文章推荐
- mybatis 高级映射和spring整合之查询缓存(5)
- Java图片居中裁剪代码
- json-c库使用总结
- MQ介绍
- 软件开发的文档与审查
- cannot resolve symbol 'XXXX'
- 队列---基本概念、顺序队列
- iOS蓝牙4.0开发流程
- sql如果存在就修改不存在就新增
- Linux 通用中断子系统
- 图像处理之玻璃水印特效(祝大家圣诞节快乐)
- 让Windows Server 2008 + IIS 7+ ASP.NET 支持10万并发请求
- 大数据社区研讨会 (第一届)
- 报错Syntax error on token "int", Dimensions expected after this token
- 中转inline hook,不需要恢复首字节的hook
- 三个枪手问题
- Zabbix监控之系统及应用日志监控报警
- IOS开发—无需自定义,修改tabbar背景颜色
- MySQL for Mac 安装和基本操作
- 删除指定链表节点