Issue
I am currently looking to know how to make a question mark URL in Spring Web. My objective is to use this example URL /person?name=Bob
to get a List<Person>
named Bob!
I don't quite get how to do so this don't hesitate to give me more details if possible!
What I tried:
@GetMapping("/person?name={someName}")
List<Person> getPersonsByName(@RequestParam String name) {
return personService.getPersonsByName(name);
}
What it does:
Since I'm doing a wrong mapping, it is not set up.
{
"timestamp": "...",
"status": 404,
"error": "Not Found",
"path": "/person"
}
Solution
@RequestParam
create ?
in URL so you should try this
@GetMapping("/person")
List<Person> getPersonsByName(@RequestParam String name) {
return personService.getPersonsByName(name);
}
Answered By - SYED MUSTAFA HUSSAIN
Answer Checked By - David Goodson (JavaFixing Volunteer)