spring mvc 后台接受string类型,对日期类型转换

来源:互联网 发布:steam网络连接错误10 编辑:程序博客网 时间:2024/05/09 14:00


  1. @InitBinder  
  2. protected  void initBinder(WebDataBinder binder) {  
  3.     SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");  
  4.     binder.registerCustomEditor(Date.classnew CustomDateEditor(dateFormat, true));  
  5. }  

方法就可以

二、注解方式:   

[java] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")  //取日期时使用  
  2. @DateTimeFormat(pattern = "yyyy-MM-dd")//存日期时使用  
  3. private Date startTime;  

0 0
原创粉丝点击