From 7a59ed2ff571e3d5657079f3c1b45f206604b3d6 Mon Sep 17 00:00:00 2001 From: chenzhihang <709011834@qq.com> Date: Tue, 22 Oct 2024 17:30:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=9C=8D=E5=8A=A1=E5=AF=B9?= =?UTF-8?q?=E6=AF=94bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/ruoyi/platform/utils/ConvertUtil.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/ConvertUtil.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/ConvertUtil.java index 52c89dd3..95bb18cd 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/ConvertUtil.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/ConvertUtil.java @@ -159,6 +159,17 @@ public class ConvertUtil { 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 compareObjects(Object obj1, Object obj2) throws IllegalAccessException { Map differences = new HashMap<>(); @@ -176,7 +187,7 @@ public class ConvertUtil { // Compare the field values 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); } }