JavaScript: Formdata append null value - NumberFormatException

半腔热情 提交于 2019-12-24 23:44:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!