Spring Boot 2.1中的URI模式匹配

问题描述 投票:0回答:1

随着第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匹配机制?

java spring spring-boot url-routing
1个回答
0
投票

蚂蚁匹配器将与/spring5/**并且正常的路径模式将适用于

@GetMapping("/spring5/{*id}")
public void methodName(@PathVariable String id)

也尝试添加@PathVariable,它将为您工作。

© www.soinside.com 2019 - 2024. All rights reserved.