随着第 5 版的推出,Spring 更改了默认的 URL 模式匹配机制 AntPathMatcher至 PathPattern类(class)。基于 Spring 5.1 版本的 Spring Boot 2.1 不遵循此更改,因为它仍然使用 AntPathMatcher
进行处理:
@GetMapping("/spring5/{*id}") //PathPattern implementation, compilation error
@GetMapping("/spring5/**") // AntPathMatcher implementation, works fine
有没有办法为 Spring Boot 2.1 应用程序启用 PathPattern
匹配机制?
最佳答案
Ant Matcher 将与
/spring5/**
和正常的路径模式将适用于
@GetMapping("/spring5/{*id}")
public void methodName(@PathVariable String id)
尝试添加@PathVariable,它会为你工作。
关于java - Spring Boot 2.1 中的 URI 模式匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59876623/