Setting default DateTimeFormat Annotation in Spring

给你一囗甜甜゛ 提交于 2019-12-02 09:11:02

As kuhajeyan mentioned, you can use binder, but not on a controller, rather on controller advice, that will apply it globally:

@ControllerAdvice
public class GlobalDateBinder {

 /* Initialize a global InitBinder for dates*/

 @InitBinder
 public void binder(WebDataBinder binder) {
  // here you can use kuhajeyan's code
 }
}

in your controller

@InitBinder
protected void initBinder(WebDataBinder binder) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/YYYY");
    binder.registerCustomEditor(Date.class, new CustomDateEditor(
            dateFormat, false));
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!