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:不能为空值
  }


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM