当前位置:网站首页>Tool class: object to map hump to underline underline hump
Tool class: object to map hump to underline underline hump
2022-07-07 06:57:00 【Wandering elephant】
package com.esint.gaplatform.sjxxdataxjclgs.util;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Obj2map {
public static Map<String, Object> objectToMap(Object obj) throws IllegalAccessException {
Map<String, Object> map = new HashMap<String, Object>();
Class<?> clazz = obj.getClass();
for (Field field : clazz.getDeclaredFields()) {
field.setAccessible(true);
String fieldName = field.getName();
String field_name = humpToLine(fieldName);
Object value = field.get(obj);
map.put(field_name, value);
}
return map;
}
private static Pattern linePattern = Pattern.compile("_(\\w)");
private static Pattern humpPattern = Pattern.compile("[A-Z]");
/** * Hump underline , Finally capitalize * @param str * @return */
public static String humpToLine(String str) {
Matcher matcher = humpPattern.matcher(str);
StringBuffer sb = new StringBuffer();
while (matcher.find()) {
matcher.appendReplacement(sb, "_" + matcher.group(0).toUpperCase());
}
matcher.appendTail(sb);
return sb.toString().toUpperCase();
}
/** * Underline to hump , Normal output * @param str * @return */
public static String lineToHump(String str) {
Matcher matcher = linePattern.matcher(str);
StringBuffer sb = new StringBuffer();
while (matcher.find()) {
matcher.appendReplacement(sb, matcher.group(1).toUpperCase());
}
matcher.appendTail(sb);
return sb.toString();
}
}
边栏推荐
- How to do sports training in venues?
- 2018年江苏省职业院校技能大赛高职组“信息安全管理与评估”赛项任务书第一阶段答案
- POI export to excel: set font, color, row height adaptation, column width adaptation, lock cells, merge cells
- LM11丨重构K线构建择时交易策略
- Stack and queue-p79-10 [2014 unified examination real question]
- 【从零开始】win10系统部署Yolov5详细过程(CPU,无GPU)
- 算法---比特位计数(Kotlin)
- 联合索引ABC的几种索引利用情况
- Google Chrome browser released patch 103.0.5060.114 to fix the 0-day vulnerability
- 二十岁的我4面拿到字节跳动offer,至今不敢相信
猜你喜欢

大咖云集|NextArch基金会云开发Meetup来啦

MATLAB小技巧(29)多项式拟合 plotfit

Matlab tips (30) nonlinear fitting lsqcurefit

Stack and queue-p79-9

From zero to one, I will teach you to build the "clip search by text" search service (2): 5 minutes to realize the prototype

品牌电商如何逆势增长?在这里预见未来!

How to share the same storage among multiple kubernetes clusters

SolidWorks的GB库(钢型材库,包括铝型材、铝管等结构)安装及使用教程(生成铝型材为例)

Anr principle and Practice
![[start from scratch] detailed process of deploying yolov5 in win10 system (CPU, no GPU)](/img/77/bd80ed602208be6a9ef8be60c6ad06.png)
[start from scratch] detailed process of deploying yolov5 in win10 system (CPU, no GPU)
随机推荐
MySQL view bin log and recover data
Kotlin之 Databinding 异常
.net 5 FluentFTP连接FTP失败问题:This operation is only allowed using a successfully authenticated context
从零到一,教你搭建「CLIP 以文搜图」搜索服务(二):5 分钟实现原型
Abnova 免疫组化服务解决方案
Programmers' daily | daily anecdotes
大促过后,销量与流量兼具,是否真的高枕无忧?
算法---比特位计数(Kotlin)
2018年江苏省职业院校技能大赛高职组“信息安全管理与评估”赛项任务书第二阶段答案
根据IP获取地市
Performance comparison between Ceres solver and g2o
Unable to debug screen program with serial port
Abnova 膜蛋白脂蛋白体技术及类别展示
MYSQL binlog相关命令
js装饰器@decorator学习笔记
数据资产管理与数据安全国内外最新趋势
【mysqld】Can't create/write to file
请问 flinksql对接cdc时 如何实现计算某个字段update前后的差异 ?
[start from scratch] detailed process of deploying yolov5 in win10 system (CPU, no GPU)
MySQL user permissions