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.
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.
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.
/url?var is a valid URL which states that you have a parameter var which is not initialized.
So by default it is initialized to empty string. That's the framework behavior.
If you don't want to see that parameter coming in HttpServletRequest::getParameterMap(), just don't use it with URL (i.e. /url should be your call)