当前位置:网站首页>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();
}
}
边栏推荐
- sqlserver多线程查询问题
- Which foreign language periodicals are famous in geology?
- MySQL view bin log and recover data
- Learning notes | data Xiaobai uses dataease to make a large data screen
- 什么情况下考虑分库分表
- MOS tube parameters μ A method of Cox
- [solution] final app status- undefined, exitcode- 16
- Abnova 膜蛋白脂蛋白体技术及类别展示
- libcurl返回curlcode说明
- This article introduces you to the characteristics, purposes and basic function examples of static routing
猜你喜欢
Installing redis and windows extension method under win system
Can 7-day zero foundation prove HCIA? Huawei certification system learning path sharing
Learning notes | data Xiaobai uses dataease to make a large data screen
MySQL view bin log and recover data
Navicat importing 15g data reports an error [2013 - lost connection to MySQL server during query] [1153: got a packet bigger]
Tkinter window selects PCD file and displays point cloud (open3d)
JWT的基础介绍
Which foreign language periodicals are famous in geology?
「运维有小邓」符合GDPR的合规要求
.net 5 FluentFTP连接FTP失败问题:This operation is only allowed using a successfully authenticated context
随机推荐
快速定量,Abbkine 蛋白质定量试剂盒BCA法来了!
企业如何进行数据治理?分享数据治理4个方面的经验总结
LM small programmable controller software (based on CoDeSys) Note 23: conversion of relative coordinates of servo motor operation (stepping motor) to absolute coordinates
Linear algebra (1)
mobx 知识点集合案例(快速入门)
Distributed ID solution
常用函数detect_image/predict
Data of all class a scenic spots in China in 2022 (13604)
Unity C# 函数笔记
学术报告系列(六) - Autonomous Driving on the journey to full autonomy
反射(二)
Which foreign language periodicals are famous in geology?
Learning records on July 4, 2022
剑指offer-高质量的代码
Etcd database source code analysis -- starting from the start function of raftnode
AddressSanitizer 技术初体验
从零到一,教你搭建「CLIP 以文搜图」搜索服务(二):5 分钟实现原型
Mysql---- import and export & View & Index & execution plan
【luogu P1971】兔兔与蛋蛋游戏(二分图博弈)
Stack and queue-p78-8 [2011 unified examination true question]