Reputation: 894
Hello i'm new in implementing Spring REST Web Service what's the cause of my error.
Here's my code
@RequestMapping(value = "/message/{regID}/name/{name}", method = RequestMethod.GET, headers = "Accept=application/json")
public String getMessage(@PathVariable String regID, @PathVariable String name) {
return "Hello Alvin!" + regID + " " + name;
}
i want to call it using the web browser but i failed to successfully invoke it but when i call single parameter of may another RequestMapping is Successfully completed.. Here is the RequestMapping that i successfully called
@RequestMapping(value = "/country/{id}", method = RequestMethod.GET, headers = "Accept=application/json")
public Country getCountryById(@PathVariable int id) {
List<Country> listOfCountries = new ArrayList<Country>();
listOfCountries = createCountryList();
for (Country country : listOfCountries) {
if (country.getId() == id)
return country;
}
return null;
}
Or How can i implement multiple parameter for my RequestMapping..?
Upvotes: 2
Views: 376
Reputation: 28519
The chances are that you're using the InternalResourceViewResolver
, in which case the methods that return String
will interpret the returned valued as a view name that will be searched inside the locations designated in the view resolver. Your no mapping found probably refers to that the framework can't find a view name that matches what you're returning
As your intention seems to be to return the text only you should simply additional map your method with @ResponseBody
which will in turn add your text to response body instead of interpreting it as a view name, so
@ResponseBody
public String getMessage(@PathVariable String regID, @PathVariable String name)
Otherwise, your mapping is just fine
Upvotes: 1
Reputation: 26034
I you have more than one path variables, you need to sepecify the identifier in @PathVariable
:
@RequestMapping(value = "/message/{regID}/name/{name}", method = RequestMethod.GET, headers = "Accept=application/json")
public String getMessage(@PathVariable("regID") String regID, @PathVariable("name") String name) {
return "Hello Alvin!" + regID + " " + name;
}
Upvotes: 0