项目中,对象属性日期为Date类型,而前台传入日期为字符串类型,使用到SpringMVC框架,需进行转换。

              注意使用springMVC框架,前台传入时间参数,需实现initBinder方法把时间字符串转换为Date对象。实现了该方法,会自动完成封装Date类型属性对象。      

  @InitBinder
  public void initBinder(WebDataBinder binder) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    dateFormat.setLenient(false);
    binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true)); //true:允许输入空值,false:不能为空值
  }

相关文章:

  • 2022-02-08
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-09
  • 2022-03-02
  • 2021-05-28
  • 2022-12-23
  • 2021-08-02
相关资源
相似解决方案