AvaTaylor
AvaTaylor

Reputation: 737

How to pass a null value for a URL parameter to Spring MVC controller?

Let's say I have a Java Spring MVC controller method like this:

@RequestMapping(value="showuser", method={RequestMethod.GET})
public ModelAndView showUser(Model model, @RequestParam Map<String,String> requestParams) throws Exception {

User has three fields (firstname, middlename, lastname) all of which are part of the unique ID for that record.

And middlename can be NULL.

I do this to view the user ...

http://localhost:8080/myapp/viewuser?firstname=Bob&middlename=Tiberius&lastname=Jones

And when middlename is NULL, my code currently passes no value for middlename, like this ...

http://localhost:8080/myapp/viewuser?firstname=Bob&middlename=&lastname=Jones

... but doesn't work because in the requestParams map, the value for middlename gets set to empty string, not NULL.

I need that value to be NULL, not empty string.

How do I pass NULL as the value for the middlename parameter?

I searched and found other answers that said to use %00 or %A0 for the value, but neither of these worked. Any ideas?

Upvotes: 1

Views: 2043

Answers (1)

Radha Mohan Maheshwari
Radha Mohan Maheshwari

Reputation: 768

Don't send middlename from frontend

Upvotes: 3

Related Questions