路径匹配规则

runtao.zhong 于 2026-08-15 发布

以前只支持 AntPathMatcher 策略, 现在提供了 PathPatternParser策略。并且可以让我们指定到底使用那种策略。

Ant风格路径用法

Ant 风格的路径模式语法具有以下规则:

例如:

注意:Ant 风格的路径模式语法中的特殊字符需要转义,如:

// Web接口测试控制器
@GetMapping("/a/b/?/{p1:[a-f]+}/**")
public String hello(HttpServletRequest request, @PathVariable("p1") String path) {
    log.info("路径变量p1: {}", path);
    String uri = request.getRequestURI();
    return uri;
}
// HttpServletRequest request 是 Servlet 官方提供的原生 HTTP 请求对象
// 第一个参数:把本次HTTP请求的完整原生对象直接注入进来
// 第二个参数:把路径变量p1的值注入进来,赋值给path