spring-bootjava-8path-variablesget-mapping

GetMapping in Springboot exclude html files in pathvariable


I have a controller with the following GetMapping

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

but I have to exclude /index.html from this GetMapping

I tried like this

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

but this is not working Do I need to write each API seperatly? Please Help me


Solution

  • Dot (.) is a special character to match any sign, you need to escape it with a backslash:

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