表单字段类型转化

当我们提交表单到action 由于类型转换错误,导致返回400 错误。

@Controller
public classMyFormController {
@InitBinder
public voidinitBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = newSimpleDateFormat("yyyy-MM-dd");
dateFormat.setLenient(false);
binder.registerCustomEditor(Date.class, newCustomDateEditor(dateFormat, false));
}
// ...
}

猜你喜欢

转载自javawxl.iteye.com/blog/2313044