springMVC前台传入字符串日期参数转化

            项目中,对象属性日期为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:不能为空值
  }

原文地址:https://www.cnblogs.com/jedjia/p/springMVC.html