@InitBinder
public void initBinder(ServletRequestDataBinder dataBinder) throws Exception {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
df.setLenient(false);
dataBinder.registerCustomEditor(Date.class, new CustomDateEditor(df, false));
}
如上代码,如果输入的参数不是yyyy-MM-dd格式的,如2010-10,服务器就会抛出一场,如何在绑定数据前检查参数的格式是否为yyyy-MM-dd格式。