gpt4 book ai didi

java - Spring HandlerInterceptor 不会拦截具有查询参数的 URL

转载 作者:行者123 更新时间:2023-12-01 10:51:52 24 4
gpt4 key购买 nike

我有一个 HandlerInterceptor,我在 spring applicationContext.xml 文件中定义了它,如下所示

    <mvc:interceptor>
<mvc:mapping path="/**/security/organizations?*" />
<bean class="com.example.interceptor.PolicyInterceptor"/>
</mvc:interceptor>

现在,如果我调用以下 URL,则上述拦截器不会拦截该请求。

http://localhost:8080/user-management/security/organizations?organizationName=AECS124

有什么线索吗?

最佳答案

Spring 使用 org.springframework.util.AntPathMatcher 类来匹配路径。根据java文档

  • ?匹配一个字符
  • * 匹配零个或多个字符
  • ** 匹配路径中的零个或多个目录

不建议在路径匹配模式中使用查询参数。它可能会变得复杂。

根据您的要求,您可以简单地使用 map

<mvc:mapping path="/**/security/organizations" />

并在拦截器类中根据请求参数编写任何进一步的逻辑。

关于java - Spring HandlerInterceptor 不会拦截具有查询参数的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33828163/

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