mirror of
https://github.com/continew-org/continew-starter.git
synced 2025-10-24 18:57:13 +08:00
perf(log): 扩展静态资源路径匹配规则
- 新增 AntPathMatcher 支持更灵活的路径匹配 - 更新 RESOURCE_PATH 列表以包含更多静态资源路径模式 - 实现 isMatchAnt 方法用于 Ant 风格路径匹配 - 添加多个新的静态资源排除路径,如 /actuator/**、/favicon.ico 等 - 修改访问日志工具类使用新的 Ant 路径匹配方法
This commit is contained in:
@@ -23,6 +23,7 @@ import jakarta.servlet.ServletContext;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.http.server.PathContainer;
|
||||
import org.springframework.util.AntPathMatcher;
|
||||
import org.springframework.web.accept.ContentNegotiationManager;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.servlet.HandlerExecutionChain;
|
||||
@@ -50,6 +51,8 @@ public class SpringWebUtils {
|
||||
private SpringWebUtils() {
|
||||
}
|
||||
|
||||
private static final AntPathMatcher matcher = new AntPathMatcher();
|
||||
|
||||
/**
|
||||
* 路径是否匹配
|
||||
*
|
||||
@@ -88,6 +91,30 @@ public class SpringWebUtils {
|
||||
return pathPattern.matches(pathContainer);
|
||||
}
|
||||
|
||||
/**
|
||||
* 路径是否匹配 - Ant 风格
|
||||
*
|
||||
* @param path 路径
|
||||
* @param pattern 匹配模式
|
||||
* @return 是否匹配
|
||||
* @since 2.4.0
|
||||
*/
|
||||
public static boolean isMatchAnt(String path, String pattern) {
|
||||
return matcher.match(pattern, path);
|
||||
}
|
||||
|
||||
/**
|
||||
* 路径是否匹配 - Ant 风格
|
||||
*
|
||||
* @param path 路径
|
||||
* @param patterns 匹配模式列表
|
||||
* @return 是否匹配
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public static boolean isMatchAnt(String path, List<String> patterns) {
|
||||
return patterns.stream().anyMatch(pattern -> isMatchAnt(path, pattern));
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消注册静态资源映射
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user