@RequestMapping(value = \"/contact.html\", method = RequestMethod.POST)
public final ModelAndView contact(
@RequestParam(value = \"name\", required = false) Opti
The answer on you question will be optional parameter first is setting to null.
In Spring HandlerMethodInvoker I found resolveRequestParam method
Object paramValue = null;
...
if (multipartRequest != null) {
...
// Check if this is multipart request and set paramValue in this case.
}
// Otherwise
if (paramValue == null) {
String[] paramValues = webRequest.getParameterValues(paramName);
if (paramValues != null) {
paramValue = (paramValues.length == 1 ? paramValues[0] : paramValues);
}
}
if (paramValue == null) {
if (defaultValue != null) {
paramValue = resolveDefaultValue(defaultValue);
}
else if (required) {
raiseMissingParameterException(paramName, paramType);
}
...
}
...
So first we check if it is a multipart request. Otherwise we get parameters values by parameter name from servlet request. Finally if parameter value null we check if parameter is required. If required we throw exception, otherwise return null.