The following URL queries the DB and returns all values correctly using requestParam as below:
http://localhost:8080/app/locateUser/search?firstname=John&lastname=Clay&id=2
@RequestParam(value = "firstname") String firstname,
@RequestParam(value = "lastname") String lastname,
@RequestParam(value = "id" ) int id
Now I want to make lastname optional(remove from URL) in like this:
http://localhost:8080/app/locateUser/search?firstname=John&id=2
or
http://localhost:8080/app/locateUser/search?firstname=John&lastname=&id=2
How do I make the url optional? I want to be able to query the DB without lastname in the URL string.
This is what I have:
@RequestParam(value = "firstname") String firstname,
@RequestParam(value = "lastname" defaultValue = "lname") String lastname,
@RequestParam(value = "id" ) int id
I've also tried
@RequestParam(value = "lastname" required=false) String lastname,
Neither seems to work. What am I missing?