| @@ -159,6 +159,17 @@ public class ConvertUtil { | |||||
| return sb.toString(); | return sb.toString(); | ||||
| } | } | ||||
| private static String toSnakeCase(String camelCase) { | |||||
| return camelCase.replaceAll( | |||||
| String.format("%s|%s|%s", | |||||
| "(?<=[a-z])(?=[A-Z])", // 小写字母后接大写字母 | |||||
| "(?<=[^A-Z])(?=[A-Z][a-z])", // 非大写字母后接大写字母开头的小写字母 | |||||
| "(?<=[A-Z])(?=[A-Z][a-z][0-9])" // 大写字母后接另一个大写字母开头的小写字母和数字(可选,根据需求调整) | |||||
| ), | |||||
| "_" | |||||
| ).toLowerCase(); | |||||
| } | |||||
| public static Map<String, String> compareObjects(Object obj1, Object obj2) throws IllegalAccessException { | public static Map<String, String> compareObjects(Object obj1, Object obj2) throws IllegalAccessException { | ||||
| Map<String, String> differences = new HashMap<>(); | Map<String, String> differences = new HashMap<>(); | ||||
| @@ -176,7 +187,7 @@ public class ConvertUtil { | |||||
| // Compare the field values | // Compare the field values | ||||
| if ((value1 !=null && !value1.equals(value2)) || (value2 !=null && !value2.equals(value1))) { | if ((value1 !=null && !value1.equals(value2)) || (value2 !=null && !value2.equals(value1))) { | ||||
| differences.put(field.getName(), "Field " + field.getName() + " differs: " + value1 + " vs " + value2); | |||||
| differences.put(toSnakeCase(field.getName()), "Field " + field.getName() + " differs: " + value1 + " vs " + value2); | |||||
| } | } | ||||
| } | } | ||||