How to set each controller a default url or requestMapping in springMVC

2087 views java

For example:the class which is a controller has a requestMapping @RequestMapping("/company") ,and it has a method named "index". In this case,how can i input a url like '/company' or '/company/' and enter the method named "index"?

answered question

1 Answer


There are several ways to do it. One of the example, to use @RequestMapping on method and specify request type:

@RequestMapping(value = "/foos", method = RequestMethod.GET)
public String getFoos() {
    return "Get some Foos";

@RequestMapping(value = "/foos", method = RequestMethod.POST)
public String postFoos() {
    return "Post some Foos";

More details and examples.

posted this

Have an answer?


Please login first before posting an answer.