Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Distinguish empty value from empty string ("") in Url query parameter

How to distinguish URL without value like this /url?var from /url?var="" in Spring MVC?

Method HttpServletRequest::getParameterMap() in controller returns "" in both ways.

I need this to separate commands from queries to specified resource.

like image 777
Mati Avatar asked May 26 '26 17:05

Mati


1 Answers

One simple way of going about doing what you want to is use the getQueryString() of HttpServletRequest. You would just check and see if the returned String contains the pattern you are looking for.

If you need something like that often (as in many controller methods) you could also easily create a custom HandlerMethodArgumentResolver that will indicate the presence of a String in the URL.

Here is the relevant Javadoc and here is an example

like image 72
geoand Avatar answered May 28 '26 07:05

geoand



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!