Reputation: 233
I have request url like http://localhost:8080/api/create/ ,and the controller has the following code
@RequestMapping(value = "/", method = RequestMethod.GET)
public ResponseEntity<String> getApiResponse(HttpServletRequest request)
throws Exception {}
How will the control comes to this method ? I thers any way in spring to do this as i want the request Mapping url to be '/' only
Upvotes: 2
Views: 150
Reputation: 852
it should be:
@RequestMapping(value = "/create", method = RequestMethod.GET)
Upvotes: 2
Reputation: 115328
If your web application is a default web application on your application server, i.e. you do no have to mention the path to application itself in your URL you have to say
@RequestMapping(value = "/*", method = RequestMethod.GET)
or
@RequestMapping(value = "/api/create/", method = RequestMethod.GET)
or put @RequestMapping
annotation on class:
@RequestMapping(value = "/api/", method = RequestMethod.GET)
and then mark getApiResponse
method with annotation
@RequestMapping(value = "/create/", method = RequestMethod.GET)
You can also mention several URLs into one @RequestMapping
annotation:
@RequestMapping(value = {"/api/", "/api", "/api/*", "/api/create/"})
Upvotes: 0
Reputation: 597016
The point of the request-mapping is to map each method to a different url. In your case:
@RequestMapping(value="/api/create")
Upvotes: 0