我是靠谱客的博主 仁爱大叔,这篇文章主要介绍springmvc中注册时间类型转换器接受Date类型,现在分享给大家,希望可以做个参考。

<span style="white-space:pre">	</span>@InitBinder
	public void initBinder(ServletRequestDataBinder binder){
		binder.registerCustomEditor(Date.class,
				new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), true));
	}

注册转换器后,就能在controller里接受时间类型的参数,和带有时间类型的实体,接收类型为yyyy-MM-dd

<span style="white-space:pre">	</span>@RequestMapping("/person1.do")
	public String toPerson(String name, Integer age, String address, Date birthday) {
		System.out.println(name+" "+age+" "+birthday );
		return "index";
	}


最后

以上就是仁爱大叔最近收集整理的关于springmvc中注册时间类型转换器接受Date类型的全部内容,更多相关springmvc中注册时间类型转换器接受Date类型内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(90)

评论列表共有 0 条评论

立即
投稿
返回
顶部