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

2078 views java
0

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

4

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)
@ResponseBody
public String getFoos() {
    return "Get some Foos";
}

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

More details and examples.

posted this

Have an answer?

JD

Please login first before posting an answer.