spring 表单提交的时候,属性为整型,页面值为空串时无法转换为空指针 。
在你的派生类里重写commandcontrollor 的initBinder方法
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder)
throws Exception {
binder.registerCustomEditor(Integer.class,new CustomNumberEditor(Integer.class,true));
}
throws Exception {
binder.registerCustomEditor(Integer.class,new CustomNumberEditor(Integer.class,true));
}
可以解决这个问题 ................... spring作者的疏忽么.....

本文介绍了解决Spring框架中表单提交时,整型属性遇到空字符串无法转换为空指针的问题。通过重写commandcontrollor的initBinder方法,并注册自定义编辑器CustomNumberEditor来实现。

144

被折叠的 条评论
为什么被折叠?



