@InitBinder
public void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
dateFormat.setLenient(false);
// true passed to CustomDateEditor constructor means convert empty
// String to null
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
public void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
dateFormat.setLenient(false);
// true passed to CustomDateEditor constructor means convert empty
// String to null
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
}
这样就可以直接收集参数而不用处理
本文介绍了一种使用@InitBinder注解进行日期格式化的方法,并通过CustomDateEditor处理空字符串转为null的情况,简化了参数收集过程。

1912

被折叠的 条评论
为什么被折叠?



