我正在使用 X-editable 插件来更新具有多个字段和数据类型的表单。表单的每个元素都有一个name
映射 DTO 内的 Java 属性的值。当使用 Ajax 提交表单时,所有值都与 Java 对象的相应字段匹配,除了TAGS 数组理论上应该匹配字符串列表但不知何故我得到了一个NumberFormatException
.
堆栈跟踪
[Request processing failed; nested exception is java.lang.NumberFormatException: For input string: ""] with root cause
java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:991)
Select2 标记模式
$('.issue-tags').editable({
pk: 22,
name: 'tags',
placement: 'top',
mode: 'popup',
select2: {
tags: ${tags},
tokenSeparators: [",", " "]
},
ajaxOptions: {
type: 'put'
}
});
“tags”属性从数据库加载值。
提交按钮
$('#btn-submit').click(function() {
$('.editable').editable('submit', {
url: './updateForm.html',
ajaxOptions: {
dataType: 'json'
},
success: function(data, config) {
...
},
error: function(errors) {
...
}
});
});
Java DTO
public class MyObjectDTO implements Serializable {
private List<String> tags = new ArrayList<String>();
...
}
Spring MVC 控制器
@RequestMapping(value="/updateForm", method = RequestMethod.POST)
public @ResponseBody String doUpdateForm(@ModelAttribute("object") MyObjectDTO object,
HttpServletRequest request) throws ParseException{
...
}
如果没有标签字段,表单会正确地将数据提交给控制器。