gpt4 book ai didi

java - 如何在 FilterRegistrationBean 中获取 @PathVariable? Spring Boot

转载 作者:行者123 更新时间:2023-12-04 14:38:12 25 4
gpt4 key购买 nike

我请求的路径是:

localhost:8080/companies/12/accounts/35

我的 Rest Controller 包含此功能,我想在 Filter 中获取 companyId 和 accountId。
@RequestMapping(value = "/companies/{companyId}/accounts/{accountId}", method = RequestMethod.PUT)
public Response editCompanyAccount(@PathVariable("companyId") long companyId, @PathVariable("accountId") long accountId,
@RequestBody @Validated CompanyAccountDto companyAccountDto,
HttpServletRequest req) throws ErrorException, InvalidKeySpecException, NoSuchAlgorithmException

是否有任何功能可用于在过滤器内接收此信息?

最佳答案

Map pathVariables = (Map) request.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);  
String companyId = (String)pathVariables.get("companyId");
String accountId= (String)pathVariables.get("accountId");

关于java - 如何在 FilterRegistrationBean 中获取 @PathVariable? Spring Boot ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36739808/

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