[removed] Formdata append null value - NumberForma

2019-08-21 18:18发布

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条回答
Evening l夕情丶
2楼-- · 2019-08-21 18:44

You can resolve this issue by adding defaultValue like below.

@RequestParam(value = "version", required = false, defaultValue = "0") Integer versionNumber

see documentation

查看更多
登录 后发表回答