如何在SpringMVC中匹配URL部分?
有没有办法计算Spring控制器中剩余的URL部分 i、 e.如果我的路径是如何在SpringMVC中匹配URL部分?,spring,spring-mvc,spring-boot,Spring,Spring Mvc,Spring Boot,有没有办法计算Spring控制器中剩余的URL部分 i、 e.如果我的路径是/user/{userId}/*,我可以获取userId参数和url的其余部分吗?那一部分 例如对于/user/1/this/is/a/path.html?a=b我应该得到 userId=1和userUrl=/this/is/a/path.html?a=b 我见过一些解决方案,也在谷歌上搜索过一些,但它们看起来有点奇怪(很可能是因为答案是针对较旧版本的Spring),所以在较新版本中,如何以干净的方式实现这一点?是的,下
/user/{userId}/*
,我可以获取userId参数和url的其余部分吗?那一部分
例如对于/user/1/this/is/a/path.html?a=b
我应该得到
userId=1
和userUrl=/this/is/a/path.html?a=b
我见过一些解决方案,也在谷歌上搜索过一些,但它们看起来有点奇怪(很可能是因为答案是针对较旧版本的Spring),所以在较新版本中,如何以干净的方式实现这一点?是的,下面是一个根据答案改编的示例 在本例中,
userId=1
和finalPath=this/is/a/path.html
@GetMapping("/user/{userId}/**")
public void get(@PathVariable("userId") String userId, HttpServletRequest request){
String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
String patternMatch = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
AntPathMatcher apm = new AntPathMatcher();
String finalPath = apm.extractPathWithinPattern(patternMatch, path);
}