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)