如何从 @GetMapping spring 注释中排除某些路径?

Aly*_*ali 5 java spring spring-mvc spring-boot

我使用Spring Boot并且我的主控制器处理所有顶级网址:

import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class IndexController {
    @GetMapping({"/*"})
    public ResponseEntity<String> handleIndex() {
        // ...
    }
}
Run Code Online (Sandbox Code Playgroud)

由于某些原因,我想/exclude_path从控制器的处理中排除路径。

像这样的东西:

@GetMapping(include={"/*"}, exclude={"/exclude_path"})
Run Code Online (Sandbox Code Playgroud)

您能回答我该怎么做吗?

小智 -1

您应该删除 \xe2\x80\x9c/*\xe2\x80\x9d ,因为它将排除所有请求。仅提供您想要的路径,这样您就不需要\xe2\x80\x99//excludepath。

\n