[removed] Formdata append null value - NumberForma

2019-08-21 18:24发布

问题:

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