gpt4 book ai didi

Spring MVC 处理程序拦截器,带有 pathparam 的排除路径模式

转载 作者:行者123 更新时间:2023-12-04 18:31:33 24 4
gpt4 key购买 nike

我已经编写了一个 HandlerInterceptorAdapter 实现,并希望排除在注册 token 时对用户进行身份验证和刷新用户的路径模式,thje 资源的 URLS 主要将电子邮件地址作为路径参数,以下哪个代码片段是有效的这样做的表格

 @Override
public void addInterceptors(InterceptorRegistry registry) {
super.addInterceptors(registry);
registry.addInterceptor(new AuthorizationInterceptor()).excludePathPatterns("/somepath/*/someresource/*");
}

或者
@Override
public void addInterceptors(InterceptorRegistry registry) {
super.addInterceptors(registry);

registry.addInterceptor(new AuthorizationInterceptor()).excludePathPatterns("/somepath/{email}/someresource/*");
}

编辑:::

使用 PatternMatcher 增强了代码,仍然无法正常工作
 @Override
public void addInterceptors(InterceptorRegistry registry) {
super.addInterceptors(registry);

registry.addInterceptor(new AuthorizationInterceptor())
.excludePathPatterns(
"/somepath",
"/somepath/*/authenticate",
"somapath/*/someresource/verify"
).pathMatcher(new AntPathMatcher());
}

最佳答案

尝试这个:

@Override
public void addInterceptors(InterceptorRegistry registry) {
super.addInterceptors(registry);

registry.addInterceptor(new AuthorizationInterceptor())
.excludePathPatterns(
"/somepath",
"/somepath/**/authenticate",
"somapath/**/someresource/verify"
).pathMatcher(new AntPathMatcher());
}

映射使用以下规则匹配 URL:
? matches one character
* matches zero or more characters
** matches zero or more directories in a path

关于Spring MVC 处理程序拦截器,带有 pathparam 的排除路径模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33864252/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com