首页 > 解决方案 > Springboot中的GetMapping排除路径变量中的html文件

问题描述

我有一个带有以下 GetMapping 的控制器

@GetMapping(value = "/{path}") 
     public ResponseEntity searchAPI(@PathVariable("path") String API_NAME)

但我必须从这个 GetMapping 中排除 /index.html

我试过这样

@GetMapping(value = "/{path:^.*(?!index.html)}") 

但这不起作用我需要单独编写每个 API 吗?请帮我

标签: spring-bootjava-8path-variablesget-mapping

解决方案


点 (.) 是匹配任何符号的特殊字符,您需要使用反斜杠对其进行转义:

@GetMapping(value = "/{path:^(?!index\.html).*}") 

推荐阅读