问题
The following client code
FormData formData = FormData(document.getElementById(formElemId));
formData.append('version', null);
when received in Server Side via Spring MVC as below
@RequestParam(value = 'version', required = false) Integer versionNumber
throws the following exception
Failed to convert value of type 'java.lang.String' to required type 'java.lang.Integer'; nested exception is java.lang.NumberFormatException: For input string: "null"
回答1:
You can resolve this issue by adding defaultValue
like below.
@RequestParam(value = "version", required = false, defaultValue = "0") Integer versionNumber
see documentation
来源:https://stackoverflow.com/questions/53205938/javascript-formdata-append-null-value-numberformatexception