码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2017-08-27 17:03:30      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:字符串日期   als   字符串   set   完成   不能   gis   new   对象   

            项目中,对象属性日期为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前台传入字符串日期参数转化

标签:字符串日期   als   字符串   set   完成   不能   gis   new   对象   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!