首页 > 编程语言 > 详细

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

时间:2017-08-27 16:52:21      阅读:366      评论:0      收藏:0      [点我收藏+]

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

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

原文:http://www.cnblogs.com/jedjia/p/springMVC.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!