@InitBinder protected void initBinder(WebDataBinder binder) { //binder.setFieldDefaultPrefix(""); //设置默认前缀
//binder.setDisallowedFields(); SimpleDateFormat d1 = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat d2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
binder.registerCustomEditor(Date.class, new CustomDateEditor(d1, true));
binder.registerCustomEditor(Date.class, "time1", new CustomDateEditor(d2,
true));
}
/**
* @Author: husToy.Wang
* @Date: 2019/8/22 10:14
* @Version 1.0
*/
//@ControllerAdvice public class AppControllerAdvice {
@InitBinder public void initBinder(WebDataBinder binder){ /*以下方法二选一,第一个无需添加MulitFormatDateEditor这个类*/
//方法1:支持一个日期格式 binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"),true));
////方法2:支持两个日期格式
////true 允许属性为空verficationController binder.registerCustomEditor(Date.class, new MulitFormatDateEditor(new SimpleDateFormat("yyyy-MM-dd"), new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"),true));