springMVC提交表单时候,日期数据正常情况下要用String来接收,如果想要用Date来接收,可以实现PropertyEditorRegistry接口,这个接口在spring-beans包下
@InitBinder
protected void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
dateFormat.setLenient(false);
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));//第二个参数是控制是否支持传入的值是空,这个值很关键,如果指定为false,那么如果前台没有传值的话就会报错
}
将这个方法放在BaseController里就行
最后
以上就是开放心情最近收集整理的关于springmvc提交表单日期用Date接收的全部内容,更多相关springmvc提交表单日期用Date接收内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复