Home > Enterprise >  Spring MVC/WebAPI equivalent of C# RoutePrefix
Spring MVC/WebAPI equivalent of C# RoutePrefix

Time:11-05

I'm used to developing in C# Web API where as well as routing attributes for individual endpoints I can also add a prefix for the controller, e,g,

[RoutePrefix("/MyController")]

However I'm developing in Java Spring Boot and although I can map individual endpoints, I can't find a way to add a prefix for all.

Is this possible?

CodePudding user response:

On spring-boot you can use the @RequestMapping("/MyController") annotation at the class level.

@RequestMapping("/MyController")
public class MyController {

    @GetMapping(value = "/helloWord") // this will become /MyController/helloWord
    public String helloWorld() {
        return "Hello World";
    }

}
  • Related