From 4374a24f79df5861683fa152e0bd75586f4000b4 Mon Sep 17 00:00:00 2001 From: xjt283525476 Date: Sat, 29 Dec 2018 14:04:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=A9=BC=E5=B3=B0=E8=BD=AC?= =?UTF-8?q?=E4=B8=8B=E5=88=92=E7=BA=BF=E6=8B=BC=E6=8E=A5=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E7=AE=80=E7=A7=B0=E7=BC=A9=E5=86=99=E4=BD=9C=E4=B8=BA=E5=89=8D?= =?UTF-8?q?=E7=BC=80=E6=97=B6=EF=BC=8C=E8=BD=AC=E6=8D=A2=E5=90=8E=E9=A6=96?= =?UTF-8?q?=E5=AD=97=E6=AF=8D=E5=90=8E=E8=BF=BD=E5=8A=A0=E4=BA=86=E4=B8=8B?= =?UTF-8?q?=E5=88=92=E7=BA=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ruoyi/common/utils/StringUtils.java | 48 +++++++++---------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/StringUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/StringUtils.java index 61450886c..b8a0f2c97 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/StringUtils.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/StringUtils.java @@ -259,38 +259,36 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils /** * 下划线转驼峰命名 */ - public static String toUnderScoreCase(String s) - { - if (s == null) - { + public static String toUnderScoreCase(String str) { + if (str == null) { return null; } StringBuilder sb = new StringBuilder(); - boolean upperCase = false; - for (int i = 0; i < s.length(); i++) - { - char c = s.charAt(i); - - boolean nextUpperCase = true; - - if (i < (s.length() - 1)) - { - nextUpperCase = Character.isUpperCase(s.charAt(i + 1)); + //前置字符是否大写 + boolean preCharIsUpperCase = true; + //当前字符是否大写 + boolean curreCharIsUpperCase = true; + //下一字符是否大写 + boolean nexteCharIsUpperCase = true; + for (int i = 0; i < str.length(); i++) { + char c = str.charAt(i); + if (i > 0) { + preCharIsUpperCase = Character.isUpperCase(str.charAt(i-1));; + } else { + preCharIsUpperCase = false; } + + curreCharIsUpperCase = Character.isUpperCase(c); - if ((i > 0) && Character.isUpperCase(c)) - { - if (!upperCase || !nextUpperCase) - { - sb.append(SEPARATOR); - } - upperCase = true; + if (i < (str.length() - 1)) { + nexteCharIsUpperCase = Character.isUpperCase(str.charAt(i + 1)); } - else - { - upperCase = false; + + if (preCharIsUpperCase && curreCharIsUpperCase && !nexteCharIsUpperCase) { + sb.append(SEPARATOR); + } else if ((i !=0 && !preCharIsUpperCase) && curreCharIsUpperCase) { + sb.append(SEPARATOR); } - sb.append(Character.toLowerCase(c)); }