| | |
| | | import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType; |
| | | import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination; |
| | | import org.apache.commons.collections.CollectionUtils; |
| | | import org.springframework.util.AntPathMatcher; |
| | | |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.util.*; |
| | |
| | | |
| | | private static final String EMPTY = ""; |
| | | |
| | | |
| | | /** |
| | | * 查找指定字符串是否匹配指定字符串列表中的任意一个字符串 |
| | | * |
| | | * @param str 指定字符串 |
| | | * @param strs 需要检查的字符串数组 |
| | | * @return 是否匹配 |
| | | */ |
| | | public static boolean matches(String str, List<String> strs) |
| | | { |
| | | if (isBlank(str) || CollectionUtils.isEmpty(strs)) |
| | | { |
| | | return false; |
| | | } |
| | | for (String pattern : strs) |
| | | { |
| | | if (isMatch(pattern, str)) |
| | | { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 判断url是否与规则配置: |
| | | * ? 表示单个字符; |
| | | * * 表示一层路径内的任意字符串,不可跨层级; |
| | | * ** 表示任意层路径; |
| | | * |
| | | * @param pattern 匹配规则 |
| | | * @param url 需要匹配的url |
| | | * @return |
| | | */ |
| | | public static boolean isMatch(String pattern, String url) |
| | | { |
| | | AntPathMatcher matcher = new AntPathMatcher(); |
| | | return matcher.match(pattern, url); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 将字符串中的某些值用指定字符代替 |
| | | * |