@DateTimeFormat在spring-context依赖下,所在包如下

@DateTimeFormat注解

当form表单中出现时间字段需要跟pojo对象中的成员变量进行数据绑定时,springmvc框架中的时间数据无法自动绑定,便会报错BindException,是在对bean的属性进行数据绑定时出了问题。这是springmvc框架的问题,若不解决次问题,页面传递回来的时间类型的数据就无法在controller中接受,也就无法完成新增用户的功能。

在pojo中,对时间类型的属性标注格式化注解@DateTimeFormat即可,如下

@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date birthday;

在上述代码中,@DateTimeFormat(pattern="yyyy-MM-dd")可以将形如1988-12-01的字符串转换为java.util.Date类型。

相关文章:

  • 2021-10-25
  • 2022-01-16
  • 2021-08-18
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-03
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案