问题描述
- @initbinder 绑定date
-
@initbinder 绑定date类型可以有两个dateformat吗@InitBinder public void initBinder(WebDataBinder binder) { SimpleDateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat dateFormat2 = new SimpleDateFormat("yyyy-MM-dd"); dateFormat1.setLenient(true); dateFormat2.setLenient(true); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat1, true)); //true:允许输入空值,false:不能为空值 binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat2, true)); //true:允许输入空值,false:不能为空值 }
时间: 2024-10-27 12:51:02