您的位置:首页 > 编程语言 > Java开发

springmvc中注册时间类型转换器接受Date类型

2015-01-20 20:33 375 查看
<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";
	}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: