From eb0a485f0deccf6f5dd7bb6e881dcbd2206b89da Mon Sep 17 00:00:00 2001 From: zuojinlong <1013239814@qq.com> Date: Tue, 23 Jul 2024 09:34:51 +0000 Subject: [PATCH] =?UTF-8?q?!479=20fix:=20=E9=A9=BC=E5=B3=B0=E8=BD=AC?= =?UTF-8?q?=E4=B8=8B=E5=88=92=E7=BA=BF=E8=A7=84=E5=88=99=E4=B8=8D=E4=B8=80?= =?UTF-8?q?=E8=87=B4=E9=97=AE=E9=A2=98=20*=20fix:=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E4=BB=A3=E7=A0=81=20*=20fix:=20https://gitee?= =?UTF-8?q?.com/mybatis-flex/mybatis-flex/issues/IAEX9U=20*=20Revert=20"fi?= =?UTF-8?q?x:=20https://gitee.com/mybatis-flex/mybatis-flex/issues/IAEX9U"?= =?UTF-8?q?=20*=20fix:=20https://gitee.com/mybatis-flex/mybatis-flex/issue?= =?UTF-8?q?s/IAEX9U?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mybatisflex/core/util/StringUtilTest.java | 39 +++++++++++++------ .../mybatisflex/processor/util/StrUtil.java | 5 ++- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/mybatis-flex-core/src/test/java/com/mybatisflex/core/util/StringUtilTest.java b/mybatis-flex-core/src/test/java/com/mybatisflex/core/util/StringUtilTest.java index a133b741..a28e3992 100644 --- a/mybatis-flex-core/src/test/java/com/mybatisflex/core/util/StringUtilTest.java +++ b/mybatis-flex-core/src/test/java/com/mybatisflex/core/util/StringUtilTest.java @@ -1,5 +1,6 @@ package com.mybatisflex.core.util; +import com.mybatisflex.processor.util.StrUtil; import org.junit.Assert; import org.junit.Test; @@ -7,27 +8,41 @@ import org.junit.Test; public class StringUtilTest { @Test - public void testCamelToUnderline(){ + public void testCamelToUnderline() { String s1 = StringUtil.camelToUnderline("AAA"); - Assert.assertEquals(s1,"aaa"); + String s1_ = StrUtil.camelToUnderline("AAA"); + Assert.assertEquals(s1, "aaa"); + Assert.assertEquals(s1_, "aaa"); String s2 = StringUtil.camelToUnderline("StudentIDRoom"); - Assert.assertEquals(s2,"student_idroom"); + String s2_ = StrUtil.camelToUnderline("StudentIDRoom"); + Assert.assertEquals(s2, "student_idroom"); + Assert.assertEquals(s2_, "student_idroom"); - String s3 =StringUtil. camelToUnderline("StudentIdRoom"); - Assert.assertEquals(s3,"student_id_room"); + String s3 = StringUtil.camelToUnderline("StudentIdRoom"); + String s3_ = StrUtil.camelToUnderline("StudentIdRoom"); + Assert.assertEquals(s3, "student_id_room"); + Assert.assertEquals(s3_, "student_id_room"); String s4 = StringUtil.camelToUnderline("Student_ID"); - Assert.assertEquals(s4,"student_id"); + String s4_ = StrUtil.camelToUnderline("Student_ID"); + Assert.assertEquals(s4, "student_id"); + Assert.assertEquals(s4_, "student_id"); - String s44 = StringUtil.camelToUnderline("StudentID"); - Assert.assertEquals(s44,"student_id"); + String s5 = StringUtil.camelToUnderline("StudentID"); + String s5_ = StrUtil.camelToUnderline("StudentID"); + Assert.assertEquals(s5, "student_id"); + Assert.assertEquals(s5_, "student_id"); - String s5 = StringUtil.camelToUnderline("Student_Id"); - Assert.assertEquals(s5,"student_id"); + String s6 = StringUtil.camelToUnderline("Student_Id"); + String s6_ = StrUtil.camelToUnderline("Student_Id"); + Assert.assertEquals(s6, "student_id"); + Assert.assertEquals(s6_, "student_id"); - String s6 = StringUtil.camelToUnderline("student_id"); - Assert.assertEquals(s6,"student_id"); + String s7 = StringUtil.camelToUnderline("student_id"); + String s7_ = StrUtil.camelToUnderline("student_id"); + Assert.assertEquals(s7, "student_id"); + Assert.assertEquals(s7_, "student_id"); } } diff --git a/mybatis-flex-processor/src/main/java/com/mybatisflex/processor/util/StrUtil.java b/mybatis-flex-processor/src/main/java/com/mybatisflex/processor/util/StrUtil.java index 34b00986..fa458f9a 100644 --- a/mybatis-flex-processor/src/main/java/com/mybatisflex/processor/util/StrUtil.java +++ b/mybatis-flex-processor/src/main/java/com/mybatisflex/processor/util/StrUtil.java @@ -55,7 +55,10 @@ public class StrUtil { for (int i = 0; i < len; i++) { char c = str.charAt(i); if (Character.isUpperCase(c) && i > 0) { - sb.append('_'); + char prev = str.charAt(i - 1); + if (!Character.isUpperCase(prev) && prev != '_') { + sb.append('_'); + } } sb.append(Character.toLowerCase(c)); }