From 69ff1efdb43f3be9253c6ed73f9932f2a781f39c Mon Sep 17 00:00:00 2001 From: RuoYi Date: Sat, 29 Dec 2018 15:18:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=A0=BC=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ruoyi/common/utils/StringUtils.java | 38 ++++++++++++------- 1 file changed, 24 insertions(+), 14 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 b8a0f2c9..767a51f6 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,34 +259,44 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils /** * 下划线转驼峰命名 */ - public static String toUnderScoreCase(String str) { - if (str == null) { + public static String toUnderScoreCase(String str) + { + if (str == null) + { return null; } StringBuilder sb = new StringBuilder(); - //前置字符是否大写 + // 前置字符是否大写 boolean preCharIsUpperCase = true; - //当前字符是否大写 + // 当前字符是否大写 boolean curreCharIsUpperCase = true; - //下一字符是否大写 + // 下一字符是否大写 boolean nexteCharIsUpperCase = true; - for (int i = 0; i < str.length(); i++) { + for (int i = 0; i < str.length(); i++) + { char c = str.charAt(i); - if (i > 0) { - preCharIsUpperCase = Character.isUpperCase(str.charAt(i-1));; - } else { + if (i > 0) + { + preCharIsUpperCase = Character.isUpperCase(str.charAt(i - 1)); + } + else + { preCharIsUpperCase = false; } - + curreCharIsUpperCase = Character.isUpperCase(c); - if (i < (str.length() - 1)) { + if (i < (str.length() - 1)) + { nexteCharIsUpperCase = Character.isUpperCase(str.charAt(i + 1)); } - - if (preCharIsUpperCase && curreCharIsUpperCase && !nexteCharIsUpperCase) { + + if (preCharIsUpperCase && curreCharIsUpperCase && !nexteCharIsUpperCase) + { sb.append(SEPARATOR); - } else if ((i !=0 && !preCharIsUpperCase) && curreCharIsUpperCase) { + } + else if ((i != 0 && !preCharIsUpperCase) && curreCharIsUpperCase) + { sb.append(SEPARATOR); } sb.append(Character.toLowerCase(c));