随着第5版的引入,Spring将默认的URL模式匹配机制从AntPathMatcher更改为PathPattern类。基于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
匹配机制?
蚂蚁匹配器将与/spring5/**
并且正常的路径模式将适用于
@GetMapping("/spring5/{*id}")
public void methodName(@PathVariable String id)
也尝试添加@PathVariable,它将为您工作。