From 87fcfe0c56666c93b1af38c7348c101cfdcad31d Mon Sep 17 00:00:00 2001
From: RuoYi <yzz_ivy@163.com>
Date: Thu, 08 Apr 2021 22:19:05 +0800
Subject: [PATCH] 优化注释
---
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/StringUtils.java | 106 +++++++----------------------------------------------
1 files changed, 14 insertions(+), 92 deletions(-)
diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/StringUtils.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/StringUtils.java
index e0bc15a..3aafe03 100644
--- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/StringUtils.java
+++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/StringUtils.java
@@ -3,6 +3,7 @@
import java.util.Collection;
import java.util.List;
import java.util.Map;
+import org.springframework.util.AntPathMatcher;
import com.ruoyi.common.core.text.StrFormatter;
/**
@@ -17,9 +18,6 @@
/** 下划线 */
private static final char SEPARATOR = '_';
-
- /** 星号 */
- private static final String START = "*";
/**
* 获取参数不为空值
@@ -261,7 +259,7 @@
}
/**
- * 下划线转驼峰命名
+ * 驼峰转下划线命名
*/
public static String toUnderScoreCase(String str)
{
@@ -413,9 +411,9 @@
{
return false;
}
- for (String testStr : strs)
+ for (String pattern : strs)
{
- if (matches(str, testStr))
+ if (isMatch(pattern, str))
{
return true;
}
@@ -424,95 +422,19 @@
}
/**
- * 查找指定字符串是否匹配指定字符串数组中的任意一个字符串
+ * 判断url是否与规则配置:
+ * ? 表示单个字符;
+ * * 表示一层路径内的任意字符串,不可跨层级;
+ * ** 表示任意层路径;
*
- * @param str 指定字符串
- * @param strs 需要检查的字符串数组
- * @return 是否匹配
+ * @param pattern 匹配规则
+ * @param url 需要匹配的url
+ * @return
*/
- public static boolean matches(String str, String... strs)
+ public static boolean isMatch(String pattern, String url)
{
- if (isEmpty(str) || isEmpty(strs))
- {
- return false;
- }
- for (String testStr : strs)
- {
- if (matches(str, testStr))
- {
- return true;
- }
- }
- return false;
- }
-
- /**
- * 查找指定字符串是否匹配
- *
- * @param str 指定字符串
- * @param pattern 需要检查的字符串
- * @return 是否匹配
- */
- public static boolean matches(String str, String pattern)
- {
- if (isEmpty(pattern) || isEmpty(str))
- {
- return false;
- }
-
- pattern = pattern.replaceAll("\\s*", ""); // 替换空格
- int beginOffset = 0; // pattern截取开始位置
- int formerStarOffset = -1; // 前星号的偏移位置
- int latterStarOffset = -1; // 后星号的偏移位置
-
- String remainingURI = str;
- String prefixPattern = "";
- String suffixPattern = "";
-
- boolean result = false;
- do
- {
- formerStarOffset = indexOf(pattern, START, beginOffset);
- prefixPattern = substring(pattern, beginOffset, formerStarOffset > -1 ? formerStarOffset : pattern.length());
-
- // 匹配前缀Pattern
- result = remainingURI.contains(prefixPattern);
- // 已经没有星号,直接返回
- if (formerStarOffset == -1)
- {
- return result;
- }
-
- // 匹配失败,直接返回
- if (!result)
- return false;
-
- if (!isEmpty(prefixPattern))
- {
- remainingURI = substringAfter(str, prefixPattern);
- }
-
- // 匹配后缀Pattern
- latterStarOffset = indexOf(pattern, START, formerStarOffset + 1);
- suffixPattern = substring(pattern, formerStarOffset + 1, latterStarOffset > -1 ? latterStarOffset : pattern.length());
-
- result = remainingURI.contains(suffixPattern);
- // 匹配失败,直接返回
- if (!result)
- return false;
-
- if (!isEmpty(suffixPattern))
- {
- remainingURI = substringAfter(str, suffixPattern);
- }
-
- // 移动指针
- beginOffset = latterStarOffset + 1;
-
- }
- while (!isEmpty(suffixPattern) && !isEmpty(remainingURI));
-
- return true;
+ AntPathMatcher matcher = new AntPathMatcher();
+ return matcher.match(pattern, url);
}
@SuppressWarnings("unchecked")
--
Gitblit v1.9.3