Date validation for Java 8 Time API in Spring

孤街醉人 提交于 2019-12-04 18:25:13

The binder.registerCustomEditor method does not support DateTimeFormatter yet but in Spring 4 you can achieve this by using @DateTimeFormat with Java 8 Date-Time (java.time) objects in your pojo.

public class MyPojo {

  @DateTimeFormat(iso = ISO.DATE)
  private LocalDate localDate1;

  // you can use pattern as well
  @DateTimeFormat(pattern = "dd.MM.yyyy HH:mm")
  private LocalDate localDate2;

  // setters & getters
}

for further reference please visit

http://blog.codeleak.pl/2014/06/spring-4-datetimeformat-with-java-8.html

http://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/format/annotation/DateTimeFormat.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!