简体   繁体   中英

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?

Don't send middlename from frontend

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM