时间转换工具

来源:互联网 发布:mac xtrafinder 编辑:程序博客网 时间:2024/04/28 23:46
package cn.tarena.ht.controller;


import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;


import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;


public abstract class BaseController {
@InitBinder
//此方法用于日期的转换,如果未加,当页面日期格式转换错误,将报400错误,实际是因为此方法
public void initBinder(WebDataBinder binder) {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
dateFormat.setLenient(true);
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
}
}
原创粉丝点击